diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 8cca03e7d..6c963dbec 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -665,8 +665,16 @@ void Tokenizer::unsupportedTypedef(const Token *tok) const std::ostringstream str; const Token *tok1 = tok; - while (tok && tok->str() != ";") + int level = 0; + while (tok) { + if (level == 0 && tok->str() == ";") + break; + else if (tok->str() == "{") + level++; + else if (tok->str() == "}") + level--; + if (tok != tok1) str << " "; str << tok->str(); @@ -694,10 +702,19 @@ void Tokenizer::unsupportedTypedef(const Token *tok) const Token * Tokenizer::deleteInvalidTypedef(Token *typeDef) { Token *tok = NULL; + int level = 0; // remove typedef but leave ; - while (typeDef->next() && typeDef->next()->str() != ";") + while (typeDef->next()) + { + if (level == 0 && typeDef->next()->str() == ";") + break; + else if (typeDef->next()->str() == "{") + level++; + else if (typeDef->next()->str() == "}") + level--; typeDef->deleteNext(); + } if (typeDef != _tokens) { diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 0efd8f757..dc19bb1ab 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -232,6 +232,7 @@ private: TEST_CASE(simplifyTypedef72); // ticket #2375 TEST_CASE(simplifyTypedef73); // ticket #2412 TEST_CASE(simplifyTypedef74); // ticket #2414 + TEST_CASE(simplifyTypedef75); // ticket #2426 TEST_CASE(simplifyTypedefFunction1); TEST_CASE(simplifyTypedefFunction2); // ticket #1685 @@ -4786,6 +4787,14 @@ private: ASSERT_EQUALS("", errout.str()); } + void simplifyTypedef75() // ticket #2426 + { + const char code[] = "typedef _Packed struct S { long l; }; \n"; + const std::string expected = ";"; + ASSERT_EQUALS(expected, sizeof_(code)); + ASSERT_EQUALS("", errout.str()); + } + void simplifyTypedefFunction1() { {