diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 3cfef4049..7358a088f 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -1942,6 +1942,8 @@ void Tokenizer::simplifyTypedefCpp() tok2 = tok2->next(); tok2->next()->insertToken("0"); } + if (Token::Match(tok2->tokAt(-1), "class|struct|union") && tok2->strAt(-1) == typeStart->str()) + tok2->deletePrevious(); tok2->str(typeStart->str()); // restore qualification if it was removed diff --git a/test/testsimplifytypedef.cpp b/test/testsimplifytypedef.cpp index 89a38f394..d321026a3 100644 --- a/test/testsimplifytypedef.cpp +++ b/test/testsimplifytypedef.cpp @@ -212,6 +212,7 @@ private: TEST_CASE(simplifyTypedef146); TEST_CASE(simplifyTypedef147); TEST_CASE(simplifyTypedef148); + TEST_CASE(simplifyTypedef149); TEST_CASE(simplifyTypedefFunction1); TEST_CASE(simplifyTypedefFunction2); // ticket #1685 @@ -3443,6 +3444,18 @@ private: ASSERT_EQUALS("int & r = i ;", tok(code)); } + void simplifyTypedef149() { // #12218 + const char* code{}; + code = "namespace N {\n" + " typedef struct S {} S;\n" + "}\n" + "void g(int);\n" + "void f() {\n" + " g(sizeof(struct N::S));\n" + "}\n"; + ASSERT_EQUALS("namespace N { struct S { } ; } void g ( int ) ; void f ( ) { g ( sizeof ( struct N :: S ) ) ; }", tok(code)); + } + void simplifyTypedefFunction1() { { const char code[] = "typedef void (*my_func)();\n"