diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index b97dd7751..2a1092196 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -7465,6 +7465,11 @@ void Tokenizer::simplifyEnum() enumName = tok1; lastValue = 0; tok1 = tok1->tokAt(2); + if (tok1->str() == "," || tok1->str() == "}") { + syntaxError(tok1); + break; + } + enumValueStart = tok1; enumValueEnd = tok1; int level = 0; diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 5cf74a1d5..cf5254d2e 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -374,6 +374,7 @@ private: TEST_CASE(enum42); // ticket #5182 (template function call in enum value) TEST_CASE(enumscope1); // ticket #3949 TEST_CASE(duplicateDefinition); // ticket #3565 + TEST_CASE(invalid_enum); // #5600 // remove "std::" on some standard functions TEST_CASE(removestd); @@ -7150,6 +7151,18 @@ private: ASSERT_EQUALS(false, tokenizer.duplicateDefinition(&x_token, tokenizer.tokens())); } + void invalid_enum() { // #5600: missing include causes invalid enum + const char code [] = "enum {\n" + " NUM_OPCODES = \n" + // #include "definition" + "};\n" + "struct bytecode {};\n" + "jv jq_next() { opcode = ((opcode) +NUM_OPCODES);\n" + "}"; + checkSimplifyEnum(code); + ASSERT_EQUALS("[test.cpp:3]: (error) syntax error\n", errout.str()); + } + void removestd() { ASSERT_EQUALS("; strcpy ( a , b ) ;", tok("; std::strcpy(a,b);")); ASSERT_EQUALS("; strcat ( a , b ) ;", tok("; std::strcat(a,b);"));