Skip to content

Commit e0ee4f2

Browse files
Fix #11775 cppcheckError with array typedef (#8581)
1 parent d152dd6 commit e0ee4f2

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

lib/tokenize.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2295,6 +2295,13 @@ void Tokenizer::simplifyTypedefCpp()
22952295
tok2 = tok2->tokAt(2);
22962296
else
22972297
tok2 = tok2->tokAt(3);
2298+
while (tok2->link()) {
2299+
tok2 = tok2->link()->next();
2300+
if (Token::simpleMatch(tok2, ";")) {
2301+
tok2 = tok2->previous();
2302+
break;
2303+
}
2304+
}
22982305
if (!tok2)
22992306
syntaxError(nullptr);
23002307

test/testsimplifytypedef.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ class TestSimplifyTypedef : public TestFixture {
231231
TEST_CASE(simplifyTypedef158);
232232
TEST_CASE(simplifyTypedef159);
233233
TEST_CASE(simplifyTypedef160);
234+
TEST_CASE(simplifyTypedef161);
234235

235236
TEST_CASE(simplifyTypedefFunction1);
236237
TEST_CASE(simplifyTypedefFunction2); // ticket #1685
@@ -3842,6 +3843,22 @@ class TestSimplifyTypedef : public TestFixture {
38423843
ASSERT_EQUALS(exp2, simplifyTypedefC(code2));
38433844
}
38443845

3846+
void simplifyTypedef161() {
3847+
const char code[] = "namespace N {\n" // #11775
3848+
" typedef int A[3];\n"
3849+
" p = new A*[n];\n"
3850+
"}\n";
3851+
const char cur[] = "namespace N { p = new int ( * [ n ] ) [ 3 ] ; }";
3852+
const char exp[] = "namespace N { p = new ( int ( * [ n ] ) [ 3 ] ) ; }";
3853+
TODO_ASSERT_EQUALS(exp, cur, tok(code));
3854+
3855+
const char code2[] = "typedef int A[3];\n"
3856+
"p = new A*[n];\n";
3857+
const char cur2[] = "p = new int ( * ) [ n ] [ 3 ] ;";
3858+
const char exp2[] = "p = new ( int ( * [ n ] ) [ 3 ] ) ;";
3859+
TODO_ASSERT_EQUALS(exp2, cur2, tok(code2));
3860+
}
3861+
38453862
void simplifyTypedefFunction1() {
38463863
{
38473864
const char code[] = "typedef void (*my_func)();\n"

0 commit comments

Comments
 (0)