diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 3acaf392f..7f1c0f77c 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -320,6 +320,8 @@ unsigned int TemplateSimplifier::templateParameters(const Token *tok) return 0; if (tok->str() != "<") return 0; + if (Token::Match(tok->previous(), "%var% <")) + return 0; tok = tok->next(); unsigned int level = 0; @@ -412,11 +414,11 @@ unsigned int TemplateSimplifier::templateParameters(const Token *tok) // ,/> while (Token::Match(tok, ">|>>")) { if (level == 0) - return ((tok->str() == ">") ? numberOfParameters : 0); + return tok->str() == ">" && !Token::Match(tok->next(), "%num%") ? numberOfParameters : 0; --level; if (tok->str() == ">>") { if (level == 0) - return numberOfParameters; + return !Token::Match(tok->next(), "%num%") ? numberOfParameters : 0; --level; } tok = tok->next(); diff --git a/test/testsimplifytemplate.cpp b/test/testsimplifytemplate.cpp index 8663fb889..3fc841a5f 100644 --- a/test/testsimplifytemplate.cpp +++ b/test/testsimplifytemplate.cpp @@ -3016,6 +3016,11 @@ private: std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp", ""); + for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) { + if (tok->str() == "var1") + (const_cast(tok))->varId(1); + } + return TemplateSimplifier::templateParameters(tokenizer.tokens()->next()); } @@ -3041,6 +3046,8 @@ private: ASSERT_EQUALS(1U, templateParameters("X x;")); ASSERT_EQUALS(2U, templateParameters("X=0> x;")); ASSERT_EQUALS(3U, templateParameters("X=0, i - 2> x;")); + ASSERT_EQUALS(0U, templateParameters("var1<1> x;")); + ASSERT_EQUALS(0U, templateParameters("X<1>2;")); } // Helper function to unit test TemplateSimplifier::getTemplateNamePosition