Fixed parsing of template in enum
This commit is contained in:
parent
e578988832
commit
3cf67014ad
|
@ -7585,18 +7585,11 @@ void Tokenizer::simplifyEnum()
|
||||||
if (Token::Match(enumValueEnd, "(|[")) {
|
if (Token::Match(enumValueEnd, "(|[")) {
|
||||||
enumValueEnd = enumValueEnd->link();
|
enumValueEnd = enumValueEnd->link();
|
||||||
continue;
|
continue;
|
||||||
} else if (isCPP() && Token::Match(enumValueEnd, "%type% <") && TemplateSimplifier::templateParameters(enumValueEnd->next()) > 1U) {
|
} else if (isCPP() && Token::Match(enumValueEnd, "%type% <") && TemplateSimplifier::templateParameters(enumValueEnd->next()) >= 1U) {
|
||||||
Token *endtoken = enumValueEnd->next();
|
Token *endtoken = enumValueEnd->next()->findClosingBracket();
|
||||||
do {
|
if (endtoken) {
|
||||||
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() == ">") {
|
|
||||||
enumValueEnd = endtoken;
|
enumValueEnd = endtoken;
|
||||||
if (Token::simpleMatch(endtoken, "> ( )"))
|
if (Token::Match(endtoken, ">|>> ( )"))
|
||||||
enumValueEnd = enumValueEnd->next();
|
enumValueEnd = enumValueEnd->next();
|
||||||
} else {
|
} else {
|
||||||
syntaxError(enumValueEnd);
|
syntaxError(enumValueEnd);
|
||||||
|
@ -8796,7 +8789,7 @@ void Tokenizer::simplifyConst()
|
||||||
tok->swapWithNext();
|
tok->swapWithNext();
|
||||||
} else if (Token::Match(tok, "%type% const") &&
|
} else if (Token::Match(tok, "%type% const") &&
|
||||||
(!tok->previous() || Token::Match(tok->previous(), "[;{}(,]")) &&
|
(!tok->previous() || Token::Match(tok->previous(), "[;{}(,]")) &&
|
||||||
tok->str().find(":") == std::string::npos &&
|
tok->str().find(':') == std::string::npos &&
|
||||||
tok->str() != "operator") {
|
tok->str() != "operator") {
|
||||||
tok->swapWithNext();
|
tok->swapWithNext();
|
||||||
}
|
}
|
||||||
|
|
|
@ -194,6 +194,7 @@ private:
|
||||||
TEST_CASE(enum41); // ticket #5212 (valgrind errors during enum simplification)
|
TEST_CASE(enum41); // ticket #5212 (valgrind errors during enum simplification)
|
||||||
TEST_CASE(enum42); // ticket #5182 (template function call in enum value)
|
TEST_CASE(enum42); // ticket #5182 (template function call in enum value)
|
||||||
TEST_CASE(enum43); // lhs in assignment
|
TEST_CASE(enum43); // lhs in assignment
|
||||||
|
TEST_CASE(enum44);
|
||||||
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
|
TEST_CASE(invalid_enum); // #5600
|
||||||
|
@ -3409,6 +3410,16 @@ private:
|
||||||
ASSERT_EQUALS("A = 1 ;", checkSimplifyEnum(code));
|
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
|
void enumscope1() { // #3949 - don't simplify enum from one function in another function
|
||||||
const char code[] = "void foo() { enum { A = 0, B = 1 }; }\n"
|
const char code[] = "void foo() { enum { A = 0, B = 1 }; }\n"
|
||||||
"void bar() { int a = A; }";
|
"void bar() { int a = A; }";
|
||||||
|
|
Loading…
Reference in New Issue