Fixed #1252 (Internal error in Cppcheck while parsing struct)

This commit is contained in:
Robert Reif 2010-01-12 17:38:36 +01:00 committed by Daniel Marjamäki
parent 7b6bf80057
commit 5e8e4fd3e9
2 changed files with 24 additions and 0 deletions

View File

@ -663,10 +663,12 @@ void Tokenizer::simplifyTypedef()
tok2 = tok2->next();
tok2->insertToken("[");
tok2 = tok2->next();
Token *tok3 = tok2;
tok2->insertToken(num->strAt(0));
tok2 = tok2->next();
tok2->insertToken("]");
tok2 = tok2->next();
Token::createMutualLinks(tok2, tok3);
}
}

View File

@ -150,6 +150,7 @@ private:
TEST_CASE(simplifyTypedef13);
TEST_CASE(simplifyTypedef14);
TEST_CASE(simplifyTypedef15);
TEST_CASE(simplifyTypedef16);
TEST_CASE(reverseArraySyntax)
TEST_CASE(simplify_numeric_condition)
@ -2490,6 +2491,27 @@ private:
}
}
void simplifyTypedef16()
{
// ticket # 1252
const char code[] = "typedef char MOT8;\n"
"typedef MOT8 CHFOO[4096];\n"
"typedef struct {\n"
" CHFOO freem;\n"
"} STRFOO;";
Tokenizer tokenizer;
std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp");
// Clear the error buffer..
errout.str("");
tokenizer.simplifyTokenList();
ASSERT_EQUALS("", errout.str());
}
void reverseArraySyntax()
{
ASSERT_EQUALS("a [ 13 ]", tok("13[a]"));