Fixed #1782 ((error) ### Internal error in Cppcheck. Please report it.)

This commit is contained in:
Robert Reif 2010-06-10 07:18:55 +02:00 committed by Daniel Marjamäki
parent e64ce2e812
commit 6b65b77acf
2 changed files with 38 additions and 1 deletions

View File

@ -1428,7 +1428,18 @@ void Tokenizer::simplifyTypedef()
tok2 = tok2->next();
// skip over name
tok2 = tok2->next();
if (tok2->next()->str() != ")")
{
tok2 = tok2->next();
// check for function and skip over args
if (tok2->next()->str() == "(")
tok2 = tok2->next()->link();
}
else
{
// syntax error
}
tok2->insertToken(")");
Token::createMutualLinks(tok2->next(), tok3);

View File

@ -200,6 +200,7 @@ private:
TEST_CASE(simplifyTypedef49); // ticket #1691
TEST_CASE(simplifyTypedef50);
TEST_CASE(simplifyTypedef51);
TEST_CASE(simplifyTypedef52); // ticket #1782
TEST_CASE(simplifyTypedefFunction1);
TEST_CASE(simplifyTypedefFunction2); // ticket #1685
@ -4066,6 +4067,31 @@ private:
ASSERT_EQUALS(expected, sizeof_(code));
}
void simplifyTypedef52() // ticket #1782
{
{
const char code[] = "typedef char (* type1)[10];\n"
"type1 foo() { }";
// The expected result..
const std::string expected("; "
"char ( * foo ( ) ) [ 10 ] { }");
ASSERT_EQUALS(expected, sizeof_(code));
checkSimplifyTypedef(code);
ASSERT_EQUALS("", errout.str());
}
{
const char code[] = "typedef char (* type1)[10];\n"
"LOCAL(type1) foo() { }";
// this is invalid C so just make sure it doesn't generate an internal error
checkSimplifyTypedef(code);
ASSERT_EQUALS("", errout.str());
}
}
void simplifyTypedefFunction1()
{
{