From 92cc17110dc010cd4ebf289b7ad4b9b8c5c47677 Mon Sep 17 00:00:00 2001 From: Simon Martin Date: Thu, 15 May 2014 21:52:57 +0200 Subject: [PATCH] Ticket #5814: Handle A::B as template parameter for enum initializers. --- lib/tokenize.cpp | 4 +++- test/testsimplifytokens.cpp | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index c288337f3..5fa0b4137 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -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; diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index a9c0f7fa7..010c94e77 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -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 {};"); } + void template45() { // #5814 + tok("namespace Constants { const int fourtytwo = 42; } " + "template struct TypeMath { " + " static const int mult = sizeof(T) * U; " + "}; " + "template struct FOO { " + " enum { value = TypeMath::something }; " + "};"); + ASSERT_EQUALS("", errout.str()); + } + void template_default_parameter() { { const char code[] = "template \n"