Ticket #5814: Handle A::B as template parameter for enum initializers.

This commit is contained in:
Simon Martin 2014-05-15 21:52:57 +02:00
parent 1385f6f7c2
commit 92cc17110d
2 changed files with 15 additions and 1 deletions

View File

@ -7566,12 +7566,14 @@ void Tokenizer::simplifyEnum()
--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())) {
while ((Token::Match(endtoken,"%any% *| [,>]") || Token::Match(endtoken,"%any% :: %any%")) && (endtoken->isName() || endtoken->isNumber())) {
endtoken = endtoken->next();
if (endtoken->str() == "*")
endtoken = endtoken->next();
if (endtoken->str() == ",")
endtoken = endtoken->next();
if (endtoken->str() == "::")
endtoken = endtoken->next();
}
if (endtoken->str() == ">") {
enumValueEnd = endtoken;

View File

@ -137,6 +137,7 @@ private:
TEST_CASE(template42); // #4878 - variadic templates
TEST_CASE(template43); // #5097 - assert due to '>>' not treated as end of template instantiation
TEST_CASE(template44); // #5297 - TemplateSimplifier::simplifyCalculations not eager enough
TEST_CASE(template45); // #5814 - syntax error reported for valid code
TEST_CASE(template_unhandled);
TEST_CASE(template_default_parameter);
TEST_CASE(template_default_type);
@ -2391,6 +2392,17 @@ private:
"class FoldedZContainer : public ZContainer<FGSTensor> {};");
}
void template45() { // #5814
tok("namespace Constants { const int fourtytwo = 42; } "
"template <class T, int U> struct TypeMath { "
" static const int mult = sizeof(T) * U; "
"}; "
"template <class T> struct FOO { "
" enum { value = TypeMath<T, Constants::fourtytwo>::something }; "
"};");
ASSERT_EQUALS("", errout.str());
}
void template_default_parameter() {
{
const char code[] = "template <class T, int n=3>\n"