diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 94bca1f99..11700536e 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -3750,6 +3750,13 @@ void Tokenizer::setVarIdPass1() for (Token *tok = list.front(); tok; tok = tok->next()) { if (tok->isOp()) continue; + if (isCPP() && Token::simpleMatch(tok, "template <")) { + Token* closingBracket = tok->next()->findClosingBracket(); + if (closingBracket) + tok = closingBracket; + continue; + } + if (tok == functionDeclEndToken) { functionDeclEndStack.pop(); functionDeclEndToken = functionDeclEndStack.empty() ? nullptr : functionDeclEndStack.top(); diff --git a/test/testvarid.cpp b/test/testvarid.cpp index c572241d2..d977d4afd 100644 --- a/test/testvarid.cpp +++ b/test/testvarid.cpp @@ -153,6 +153,7 @@ private: TEST_CASE(varid_templateNamespaceFuncPtr); // #4172 TEST_CASE(varid_templateArray); TEST_CASE(varid_templateParameter); // #7046 set varid for "X": std::array Y; + TEST_CASE(varid_templateParameterFunctionPointer); // #11050 TEST_CASE(varid_templateUsing); // #5781 #7273 TEST_CASE(varid_not_template_in_condition); // #7988 TEST_CASE(varid_cppcast); // #6190 @@ -2358,6 +2359,17 @@ private: } } + void varid_templateParameterFunctionPointer() { + { + const char code[] = "template \n" + "struct a;\n"; + + ASSERT_EQUALS("1: template < class , void ( * F ) ( ) >\n" + "2: struct a ;\n", + tokenize(code)); + } + } + void varid_templateUsing() { // #5781 #7273 const char code[] = "template using X = Y;\n" "X x;";