diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 5c28bdb64..f9035e9a3 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -1241,10 +1241,10 @@ bool TemplateSimplifier::simplifyNumericCalculations(Token *tok) // TODO: This is not the correct class for simplifyCalculations(), so it // should be moved away. -bool TemplateSimplifier::simplifyCalculations(Token *start, const Token * const end) +bool TemplateSimplifier::simplifyCalculations(Token *_tokens) { bool ret = false, goback = false; - for (Token *tok = start; tok != end; tok = tok->next()) { + for (Token *tok = _tokens; tok; tok = tok->next()) { if (goback) { tok = tok->previous(); goback = false; @@ -1527,6 +1527,7 @@ bool TemplateSimplifier::simplifyTemplateInstantiations( for (std::list::const_iterator iter2 = templateInstantiations.begin(); iter2 != templateInstantiations.end(); ++iter2) { if (numberOfTemplateInstantiations != templateInstantiations.size()) { numberOfTemplateInstantiations = templateInstantiations.size(); + simplifyCalculations(tokenlist.front()); ++recursiveCount; if (recursiveCount > 100) { // bail out.. @@ -1541,8 +1542,6 @@ bool TemplateSimplifier::simplifyTemplateInstantiations( if (iter2->name != templateDeclaration.name) continue; - simplifyCalculations(iter2->token->next(), iter2->token->linkAt(1)); - if (!matchSpecialization(tok->tokAt(namepos), iter2->token, specializations)) continue; diff --git a/lib/templatesimplifier.h b/lib/templatesimplifier.h index 232b02f59..a58b58af6 100644 --- a/lib/templatesimplifier.h +++ b/lib/templatesimplifier.h @@ -224,12 +224,11 @@ public: /** * Simplify constant calculations such as "1+2" => "3". * This also performs simple cleanup of parentheses etc. - * @param start start token - * @param end end token + * @param _tokens start token * @return true if modifications to token-list are done. * false if no modifications are done. */ - static bool simplifyCalculations(Token *start, const Token *end = nullptr); + static bool simplifyCalculations(Token *_tokens); private: /** diff --git a/test/testsimplifytemplate.cpp b/test/testsimplifytemplate.cpp index 4828c612c..464fdf985 100644 --- a/test/testsimplifytemplate.cpp +++ b/test/testsimplifytemplate.cpp @@ -1097,7 +1097,7 @@ private: "struct Factorial<4> { enum FacHelper { value = 4 * Factorial<3> :: value } ; } ; " "struct Factorial<3> { enum FacHelper { value = 3 * Factorial<2> :: value } ; } ; " "struct Factorial<2> { enum FacHelper { value = 2 * Factorial<1> :: value } ; } ; " - "struct Factorial<1> { enum FacHelper { value = Factorial<0> :: value } ; } ;"; + "struct Factorial<1> { enum FacHelper { value = Factorial < 0 > :: value } ; } ;"; ASSERT_EQUALS(exp, tok(code)); }