Syntax error on invalid enum (#5600)
This commit is contained in:
parent
b6276058da
commit
6395cb9b95
|
@ -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;
|
||||
|
|
|
@ -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);"));
|
||||
|
|
Loading…
Reference in New Issue