Merge pull request #434 from simartin/ticket_6121

Ticket #6121: Report a syntax error for invalid enum initializers.
This commit is contained in:
PKEuS 2014-09-13 21:11:19 +02:00
commit 27459761c9
2 changed files with 8 additions and 1 deletions

View File

@ -7698,7 +7698,7 @@ void Tokenizer::simplifyEnum()
enumName = tok1;
lastValue = 0;
tok1 = tok1->tokAt(2);
if (tok1->str() == "," || tok1->str() == "}") {
if (tok1->str() == "," || Token::Match(tok1, "{|}")) {
syntaxError(tok1);
break;
}

View File

@ -68,6 +68,7 @@ private:
TEST_CASE(tokenize31); // #3503 (Wrong handling of member function taking function pointer as argument)
TEST_CASE(tokenize32); // #5884 (fsanitize=undefined: left shift of negative value -10000 in lib/templatesimplifier.cpp:852:46)
TEST_CASE(tokenize33); // #5780 Various crashes on valid template code
TEST_CASE(tokenize34); // #6121 (crash upon invalid enum)
// don't freak out when the syntax is wrong
TEST_CASE(wrong_syntax1);
@ -918,6 +919,12 @@ private:
ASSERT_THROW(tokenizeAndStringify(code, true), InternalError);
}
void tokenize34() { // #6121
const char code[] = "enum E { f = {} };\n"
"int a = f;";
ASSERT_THROW(tokenizeAndStringify(code, true), InternalError);
}
void wrong_syntax1() {
{
const char code[] ="TR(kvmpio, PROTO(int rw), ARGS(rw), TP_(aa->rw;))";