diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 99ff4bb37..9839118c0 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -1201,7 +1201,7 @@ void Tokenizer::simplifyTypedef() tok2 = tok2->next(); } } - } else if (tok2->tokAt(-2) && Token::Match(tok2->tokAt(-2), "%type% *|&")) { + } else if (Token::Match(tok2->tokAt(-2), "%type% *|&")) { // Ticket #5868: Don't substitute variable names } else if (tok2->previous()->str() != ".") { simplifyType = true; @@ -1264,6 +1264,8 @@ void Tokenizer::simplifyTypedef() structRemoved = true; typeStart = typeStart->next(); } + if (typeStart->str() == "struct" && Token::Match(tok2, "%name% ::")) + typeStart = typeStart->next(); // start substituting at the typedef name by replacing it with the type tok2->str(typeStart->str()); diff --git a/test/testsimplifytypedef.cpp b/test/testsimplifytypedef.cpp index 9dc88486c..89c9481f5 100644 --- a/test/testsimplifytypedef.cpp +++ b/test/testsimplifytypedef.cpp @@ -150,6 +150,7 @@ private: TEST_CASE(simplifyTypedef111); // ticket #6345 TEST_CASE(simplifyTypedef112); // ticket #6048 TEST_CASE(simplifyTypedef113); // ticket #7030 + TEST_CASE(simplifyTypedef114); // ticket #7058 - skip "struct", AB::.. TEST_CASE(simplifyTypedefFunction1); TEST_CASE(simplifyTypedefFunction2); // ticket #1685 @@ -2414,6 +2415,13 @@ private: ASSERT_EQUALS(expected, tok(code)); } + void simplifyTypedef114() { // ticket #7058 + const char code[] = "typedef struct { enum {A,B}; } AB;\n" + "x=AB::B;"; + const char expected[] = "struct AB { } ; x = 1 ;"; + ASSERT_EQUALS(expected, tok(code)); + } + void simplifyTypedefFunction1() { { const char code[] = "typedef void (*my_func)();\n"