Fixed #2449 (segfault in tokenize.cpp, incorrect parsing)
This commit is contained in:
parent
da998fec68
commit
f72fd6960e
|
@ -2385,6 +2385,27 @@ bool Tokenizer::tokenize(std::istream &code,
|
||||||
// Remove __builtin_expect, likely and unlikely
|
// Remove __builtin_expect, likely and unlikely
|
||||||
simplifyBuiltinExpect();
|
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..
|
// typedef..
|
||||||
simplifyTypedef();
|
simplifyTypedef();
|
||||||
|
|
||||||
|
|
|
@ -511,6 +511,13 @@ private:
|
||||||
ASSERT_EQUALS("", tokenizeAndStringify(code.c_str(), true));
|
ASSERT_EQUALS("", tokenizeAndStringify(code.c_str(), true));
|
||||||
ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str());
|
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()
|
void minus()
|
||||||
|
|
Loading…
Reference in New Issue