Fixed parsing of template in enum

This commit is contained in:
PKEuS 2015-08-14 11:07:42 +02:00
parent e578988832
commit 3cf67014ad
2 changed files with 16 additions and 12 deletions

View File

@ -7585,18 +7585,11 @@ void Tokenizer::simplifyEnum()
if (Token::Match(enumValueEnd, "(|[")) {
enumValueEnd = enumValueEnd->link();
continue;
} else if (isCPP() && Token::Match(enumValueEnd, "%type% <") && TemplateSimplifier::templateParameters(enumValueEnd->next()) > 1U) {
Token *endtoken = enumValueEnd->next();
do {
endtoken = endtoken->next();
if (Token::Match(endtoken, "*|,|::|typename"))
endtoken = endtoken->next();
if (endtoken->str() == "<" && TemplateSimplifier::templateParameters(endtoken))
endtoken = endtoken->findClosingBracket();
} while (Token::Match(endtoken, "%name%|%num% *| [,>]") || Token::Match(endtoken, "%name%|%num% ::|< %any%"));
if (endtoken->str() == ">") {
} else if (isCPP() && Token::Match(enumValueEnd, "%type% <") && TemplateSimplifier::templateParameters(enumValueEnd->next()) >= 1U) {
Token *endtoken = enumValueEnd->next()->findClosingBracket();
if (endtoken) {
enumValueEnd = endtoken;
if (Token::simpleMatch(endtoken, "> ( )"))
if (Token::Match(endtoken, ">|>> ( )"))
enumValueEnd = enumValueEnd->next();
} else {
syntaxError(enumValueEnd);
@ -8796,7 +8789,7 @@ void Tokenizer::simplifyConst()
tok->swapWithNext();
} else if (Token::Match(tok, "%type% const") &&
(!tok->previous() || Token::Match(tok->previous(), "[;{}(,]")) &&
tok->str().find(":") == std::string::npos &&
tok->str().find(':') == std::string::npos &&
tok->str() != "operator") {
tok->swapWithNext();
}

View File

@ -194,6 +194,7 @@ private:
TEST_CASE(enum41); // ticket #5212 (valgrind errors during enum simplification)
TEST_CASE(enum42); // ticket #5182 (template function call in enum value)
TEST_CASE(enum43); // lhs in assignment
TEST_CASE(enum44);
TEST_CASE(enumscope1); // ticket #3949
TEST_CASE(duplicateDefinition); // ticket #3565
TEST_CASE(invalid_enum); // #5600
@ -3409,6 +3410,16 @@ private:
ASSERT_EQUALS("A = 1 ;", checkSimplifyEnum(code));
}
void enum44() {
const char code1[] = "enum format_t { YYYYMMDD = datemask_traits< datemask<'Y', 'Y', 'Y', 'Y', '/', 'M', 'M', '/', 'D', 'D'> >::value, };\n"
"YYYYMMDD;";
ASSERT_EQUALS("( datemask_traits < datemask < 'Y' , 'Y' , 'Y' , 'Y' , '/' , 'M' , 'M' , '/' , 'D' , 'D' > > :: value ) ;", checkSimplifyEnum(code1));
const char code2[] = "enum format_t { YYYYMMDD = datemask_traits< datemask<'Y', 'Y', 'Y', 'Y', '/', 'M', 'M', '/', 'D', 'D'>>::value, };\n"
"YYYYMMDD;";
ASSERT_EQUALS("( datemask_traits < datemask < 'Y' , 'Y' , 'Y' , 'Y' , '/' , 'M' , 'M' , '/' , 'D' , 'D' > > :: value ) ;", checkSimplifyEnum(code2));
}
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; }";