diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 6fb4c81e6..1214667c0 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -168,7 +168,7 @@ const Token* TemplateSimplifier::hasComplicatedSyntaxErrorsInTemplates(Token *to unsigned int TemplateSimplifier::templateParameters(const Token *tok) { - unsigned int numberOfParameters = 0; + unsigned int numberOfParameters = 1; if (!tok) return 0; @@ -179,9 +179,6 @@ unsigned int TemplateSimplifier::templateParameters(const Token *tok) unsigned int level = 0; while (tok) { - if (level == 0) - ++numberOfParameters; - // skip const if (Token::Match(tok, "const %any%")) tok = tok->next(); @@ -217,20 +214,26 @@ unsigned int TemplateSimplifier::templateParameters(const Token *tok) if (tok->str() == "<") { ++level; tok = tok->next(); - continue; } // ,/> - while (tok->str() == ">") { + while (tok->str() == ">" || tok->str() == ">>") { if (level == 0) return numberOfParameters; --level; + if (tok->str() == ">>") { + if (level == 0) + return numberOfParameters; + --level; + } tok = tok->next(); if (!tok) return 0; } if (tok->str() != ",") - break; + continue; + if (level == 0) + ++numberOfParameters; tok = tok->next(); } return 0; diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index bab83cd9f..4b235b32f 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -224,6 +224,7 @@ private: TEST_CASE(varid49); // #3799 - void f(std::vector) TEST_CASE(varid50); // #3760 - explicit TEST_CASE(varid51); // don't set varid for template function + TEST_CASE(varid52); // Set varid for nested templates TEST_CASE(varid_cpp_keywords_in_c_code); TEST_CASE(varidFunctionCall1); TEST_CASE(varidFunctionCall2); @@ -3380,6 +3381,17 @@ private: tokenizeDebugListing(code, false, "test.cpp")); } + void varid52() { + const std::string code("A::D> e;\n" + "B< C<> > b[10];\n" + "B> c[10];"); + ASSERT_EQUALS("\n\n##file 0\n" + "1: A < B < C > :: D > e@1 ;\n" + "2: B < C < > > b@2 [ 10 ] ;\n" + "3: B < C < > > c@3 [ 10 ] ;\n", + tokenizeDebugListing(code, false, "test.cpp")); + } + void varid_cpp_keywords_in_c_code() { const char code[] = "void f() {\n" " delete d;\n"