Fixed #5182 (Tokenizer::simplifyEnum: template function call as enum value)
This commit is contained in:
parent
92305ed1f9
commit
762806499f
|
@ -7718,6 +7718,24 @@ void Tokenizer::simplifyEnum()
|
|||
++level;
|
||||
else if (Token::Match(enumValueEnd->next(), "]|)"))
|
||||
--level;
|
||||
else if (Token::Match(enumValueEnd, "%type% <") && isCPP() && TemplateSimplifier::templateParameters(enumValueEnd->next()) > 1U) {
|
||||
Token *endtoken = enumValueEnd->tokAt(2);
|
||||
while (Token::Match(endtoken,"%any% *| [,>]") && (endtoken->isName() || endtoken->isNumber())) {
|
||||
endtoken = endtoken->next();
|
||||
if (endtoken->str() == "*")
|
||||
endtoken = endtoken->next();
|
||||
if (endtoken->str() == ",")
|
||||
endtoken = endtoken->next();
|
||||
}
|
||||
if (endtoken->str() == ">") {
|
||||
enumValueEnd = endtoken;
|
||||
if (Token::simpleMatch(endtoken, "> ( )"))
|
||||
enumValueEnd = enumValueEnd->next();
|
||||
} else {
|
||||
syntaxError(enumValueEnd);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
enumValueEnd = enumValueEnd->next();
|
||||
}
|
||||
|
|
|
@ -376,6 +376,7 @@ private:
|
|||
TEST_CASE(enum39); // ticket #5145 (fp variable hides enum)
|
||||
TEST_CASE(enum40);
|
||||
TEST_CASE(enum41); // ticket #5212 (valgrind errors during enum simplification)
|
||||
TEST_CASE(enum42); // ticket #5182 (template function call in enum value)
|
||||
TEST_CASE(enumscope1); // ticket #3949
|
||||
TEST_CASE(duplicateDefinition); // ticket #3565
|
||||
|
||||
|
@ -7513,6 +7514,12 @@ private:
|
|||
ASSERT_EQUALS("int x ; x = ( 1 ) | 2 ;", checkSimplifyEnum(code));
|
||||
}
|
||||
|
||||
void enum42() { // ticket #5182 (template function call in template value)
|
||||
const char code[] = "enum { A = f<int,2>() };\n"
|
||||
"a = A;";
|
||||
ASSERT_EQUALS("a = f < int , 2 > ( ) ;", checkSimplifyEnum(code));
|
||||
}
|
||||
|
||||
void enumscope1() { // #3949 - don't simplify enum from one function in another function
|
||||
const char code[] = "void foo() { enum { A = 0, B = 1 }; }\n"
|
||||
"void bar() { int a = A; }";
|
||||
|
|
Loading…
Reference in New Issue