Tokenizer::simplifyTypedef: Fix bug with arrays

This commit is contained in:
Daniel Marjamäki 2018-10-21 21:15:34 +02:00
parent 64fbffc90d
commit f9b132e831
2 changed files with 13 additions and 7 deletions

View File

@ -1501,13 +1501,11 @@ void Tokenizer::simplifyTypedef()
}
} else if (typeOf) {
tok2 = TokenList::copyTokens(tok2, argStart, argEnd);
} else if (tok2->strAt(2) == "[") {
do {
if (!tok2->linkAt(2))
syntaxError(tok2);
tok2 = tok2->linkAt(2)->previous();
} while (tok2->strAt(2) == "[");
} else if (Token::Match(tok2, "%name% [")) {
while (Token::Match(tok2, "%name%|] [")) {
tok2 = tok2->linkAt(1);
}
tok2 = tok2->previous();
}
if (arrayStart && arrayEnd) {

View File

@ -162,6 +162,7 @@ private:
TEST_CASE(simplifyTypedef122); // segmentation fault
TEST_CASE(simplifyTypedef123); // ticket #7406
TEST_CASE(simplifyTypedef124); // ticket #7792
TEST_CASE(simplifyTypedef125); // #8749 - typedef char A[10]; p = new A[1];
TEST_CASE(simplifyTypedefFunction1);
TEST_CASE(simplifyTypedefFunction2); // ticket #1685
@ -2526,6 +2527,13 @@ private:
}
void simplifyTypedef125() { // #8749
const char code[] = "typedef char A[3];\n"
"char (*p)[3] = new A[4];";
const char exp [] = "char ( * p ) [ 3 ] = new char [ 4 ] [ 3 ] ;";
ASSERT_EQUALS(exp, tok(code, false));
}
void simplifyTypedefFunction1() {
{
const char code[] = "typedef void (*my_func)();\n"