From 40af889df090c814015207a80c36c3dda2d1d1e8 Mon Sep 17 00:00:00 2001 From: IOBYTE Date: Sat, 23 Mar 2019 05:45:38 -0400 Subject: [PATCH] Fixed #9053 (simplifyTypedef: wrong simplification of '(const d)' when 'd' is a array) (#1751) * Fixed #9053 (simplifyTypedef: wrong simplification of '(const d)' when 'd' is a array) * fix whitespace --- lib/tokenize.cpp | 3 ++- test/testsimplifytypedef.cpp | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 0cb0e08ed..0d96de87b 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -1241,7 +1241,8 @@ void Tokenizer::simplifyTypedef() // check for cast: (some_typedef) A or static_cast(A) // todo: check for more complicated casts like: (const some_typedef *)A if ((tok2->previous()->str() == "(" && tok2->next()->str() == ")" && tok2->strAt(-2) != "sizeof") || - (tok2->previous()->str() == "<" && Token::simpleMatch(tok2->next(), "> ("))) + (tok2->previous()->str() == "<" && Token::simpleMatch(tok2->next(), "> (")) || + Token::Match(tok2->tokAt(-2), "( const %name% )")) inCast = true; // check for template parameters: t t1 diff --git a/test/testsimplifytypedef.cpp b/test/testsimplifytypedef.cpp index 4a0031bd2..ed49e2480 100644 --- a/test/testsimplifytypedef.cpp +++ b/test/testsimplifytypedef.cpp @@ -165,6 +165,7 @@ private: TEST_CASE(simplifyTypedef125); // #8749 - typedef char A[10]; p = new A[1]; TEST_CASE(simplifyTypedef126); // ticket #5953 TEST_CASE(simplifyTypedef127); // ticket #8878 + TEST_CASE(simplifyTypedef128); // ticket #9053 TEST_CASE(simplifyTypedefFunction1); TEST_CASE(simplifyTypedefFunction2); // ticket #1685 @@ -2551,6 +2552,17 @@ private: ASSERT_EQUALS(exp, tok(code, false)); } + void simplifyTypedef128() { // #9053 + const char code[] = "typedef int d[4];\n" + "void f() {\n" + " dostuff((const d){1,2,3,4});\n" + "}"; + const char exp [] = "void f ( ) { " + "dostuff ( ( const int [ 4 ] ) { 1 , 2 , 3 , 4 } ) ; " + "}"; + ASSERT_EQUALS(exp, tok(code, false)); + } + void simplifyTypedefFunction1() { { const char code[] = "typedef void (*my_func)();\n"