Fixed #5182 (Tokenizer::simplifyEnum: template function call as enum value)

This commit is contained in:
Daniel Marjamäki 2013-12-16 07:07:00 +01:00
parent 92305ed1f9
commit 762806499f
2 changed files with 25 additions and 0 deletions

View File

@ -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();
}

View File

@ -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; }";