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

This commit is contained in:
Robert Reif 2010-02-18 07:24:24 +01:00 committed by Daniel Marjamäki
parent 9e61e7dda8
commit 5c6ec0364d
2 changed files with 25 additions and 1 deletions

View File

@ -774,10 +774,13 @@ void Tokenizer::simplifyTypedef()
{
if (tok2->next()->str() == "(")
tok2 = tok2->next()->link();
else
else if (tok2->next()->str() != "[")
{
tok2 = tok2->next();
while (Token::Match(tok2, "*|&"))
tok2 = tok2->next();
// skip over typedef parameter
if (tok2->next()->str() == "(")
{

View File

@ -170,6 +170,7 @@ private:
TEST_CASE(simplifyTypedef31);
TEST_CASE(simplifyTypedef32);
TEST_CASE(simplifyTypedef33);
TEST_CASE(simplifyTypedef34); // ticket #1411
TEST_CASE(reverseArraySyntax)
TEST_CASE(simplify_numeric_condition)
@ -3167,6 +3168,26 @@ private:
ASSERT_EQUALS(expected, tok(code, false));
}
void simplifyTypedef34()
{
// ticket #1411
const char code[] = "class X { };\n"
"typedef X (*foofunc)(const X&);\n"
"int main()\n"
"{\n"
" foofunc *Foo = new foofunc[2];\n"
"}";
const char expected[] =
"class X { } ; "
"; "
"int main ( ) "
"{ "
"X ( * * Foo ) ( const X & ) = new X ( * ) ( const X & ) [ 2 ] ; "
"}";
ASSERT_EQUALS(expected, tok(code, false));
}
void reverseArraySyntax()
{
ASSERT_EQUALS("a [ 13 ]", tok("13[a]"));