diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 7b7951af9..249ebc656 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2385,6 +2385,27 @@ bool Tokenizer::tokenize(std::istream &code, // Remove __builtin_expect, likely and unlikely simplifyBuiltinExpect(); + // #2449: syntax error: enum with typedef in it + for (const Token *tok = _tokens; tok; tok = tok->next()) + { + if (Token::Match(tok, "enum %var% {")) + { + for (const Token *tok2 = tok->tokAt(3); tok2; tok2 = tok2->next()) + { + if (tok2->str() == "typedef") + { + syntaxError(tok2); + deallocateTokens(); + return false; + } + else if (tok2->str() == "}") + { + break; + } + } + } + } + // typedef.. simplifyTypedef(); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 25089a374..ee5207b96 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -511,6 +511,13 @@ private: ASSERT_EQUALS("", tokenizeAndStringify(code.c_str(), true)); ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str()); } + + { + errout.str(""); + const std::string code("enum ABC { A,B, typedef enum { C } };"); + tokenizeAndStringify(code.c_str(), true); + ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str()); + } } void minus()