Fixed #1298 ((error) ### Internal error in Cppcheck. Please report it. (typedef in fun proto))

This commit is contained in:
Robert Reif 2010-01-22 20:26:07 +01:00 committed by Daniel Marjamäki
parent 1552c0f7f2
commit 13ca2510cc
2 changed files with 43 additions and 5 deletions

View File

@ -683,11 +683,14 @@ void Tokenizer::simplifyTypedef()
if (!inCast)
{
tok2 = tok2->next();
if (tok2->next()->str() != ")" && tok2->next()->str() != ",")
{
tok2 = tok2->next();
// skip over typedef parameter
if (tok2->next()->str() == "(")
tok2 = tok2->next()->link();
// skip over typedef parameter
if (tok2->next()->str() == "(")
tok2 = tok2->next()->link();
}
}
tok2->insertToken(")");
@ -949,7 +952,7 @@ bool Tokenizer::tokenize(std::istream &code, const char FileName[])
removeExceptionSpecifications(_tokens);
// simplify function pointers
simplifyFunctionPointers();
// simplifyFunctionPointers();
setVarId();
if (!validate())

View File

@ -160,6 +160,7 @@ private:
TEST_CASE(simplifyTypedef22);
TEST_CASE(simplifyTypedef23);
TEST_CASE(simplifyTypedef24);
TEST_CASE(simplifyTypedef25);
TEST_CASE(reverseArraySyntax)
TEST_CASE(simplify_numeric_condition)
@ -2815,6 +2816,40 @@ private:
}
}
void simplifyTypedef25()
{
{
// ticket #1298
const char code[] = "typedef void (*fill_names_f) (const char *);\n"
"struct vfs_class {\n"
" void (*fill_names) (struct vfs_class *me, fill_names_f);\n"
"}";
const char expected[] =
"; "
"struct vfs_class { "
"void ( * fill_names ) ( struct vfs_class * me , void ( * ) ( const char * ) ) ; "
"}";
ASSERT_EQUALS(expected, tok(code, false));
}
{
const char code[] = "typedef void (*fill_names_f) (const char *);\n"
"struct vfs_class {\n"
" void (*fill_names) (fill_names_f, struct vfs_class *me);\n"
"}";
const char expected[] =
"; "
"struct vfs_class { "
"void ( * fill_names ) ( void ( * ) ( const char * ) , struct vfs_class * me ) ; "
"}";
ASSERT_EQUALS(expected, tok(code, false));
}
}
void reverseArraySyntax()
{
ASSERT_EQUALS("a [ 13 ]", tok("13[a]"));