Syntax error on invalid enum (#5600)

This commit is contained in:
PKEuS 2014-03-22 19:30:06 +01:00
parent b6276058da
commit 6395cb9b95
2 changed files with 18 additions and 0 deletions

View File

@ -7465,6 +7465,11 @@ void Tokenizer::simplifyEnum()
enumName = tok1; enumName = tok1;
lastValue = 0; lastValue = 0;
tok1 = tok1->tokAt(2); tok1 = tok1->tokAt(2);
if (tok1->str() == "," || tok1->str() == "}") {
syntaxError(tok1);
break;
}
enumValueStart = tok1; enumValueStart = tok1;
enumValueEnd = tok1; enumValueEnd = tok1;
int level = 0; int level = 0;

View File

@ -374,6 +374,7 @@ private:
TEST_CASE(enum42); // ticket #5182 (template function call in enum value) TEST_CASE(enum42); // ticket #5182 (template function call in enum value)
TEST_CASE(enumscope1); // ticket #3949 TEST_CASE(enumscope1); // ticket #3949
TEST_CASE(duplicateDefinition); // ticket #3565 TEST_CASE(duplicateDefinition); // ticket #3565
TEST_CASE(invalid_enum); // #5600
// remove "std::" on some standard functions // remove "std::" on some standard functions
TEST_CASE(removestd); TEST_CASE(removestd);
@ -7150,6 +7151,18 @@ private:
ASSERT_EQUALS(false, tokenizer.duplicateDefinition(&x_token, tokenizer.tokens())); 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() { void removestd() {
ASSERT_EQUALS("; strcpy ( a , b ) ;", tok("; std::strcpy(a,b);")); ASSERT_EQUALS("; strcpy ( a , b ) ;", tok("; std::strcpy(a,b);"));
ASSERT_EQUALS("; strcat ( a , b ) ;", tok("; std::strcat(a,b);")); ASSERT_EQUALS("; strcat ( a , b ) ;", tok("; std::strcat(a,b);"));