diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index a20b1330c..035042369 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -555,7 +555,7 @@ void TemplateSimplifier::getTemplateInstantiations() const Token *tok2 = Token::findmatch(tok, "{|;"); if (tok2 && tok2->str() == "{") tok = tok2->link(); - } else if (Token::Match(tok->previous(), "(|{|}|;|=|>|<<|:|. %name% ::|<") || + } else if (Token::Match(tok->previous(), "(|{|}|;|=|>|<<|:|.|*|& %name% ::|<") || Token::Match(tok->previous(), "%type% %name% ::|<") || Token::Match(tok->tokAt(-2), "[,:] private|protected|public %name% ::|<")) { diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 804b37032..7d98b9e5a 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -6073,7 +6073,7 @@ void Tokenizer::simplifyStaticConst() if (behindOther) break; if (!Token::Match(leftTok, "%type%|struct|::") || - (isCPP() && Token::Match(leftTok, "private:|protected:|public:|operator"))) { + (isCPP() && Token::Match(leftTok, "private:|protected:|public:|operator|template"))) { break; } } diff --git a/test/testsimplifytemplate.cpp b/test/testsimplifytemplate.cpp index c3bd02c76..98adff213 100644 --- a/test/testsimplifytemplate.cpp +++ b/test/testsimplifytemplate.cpp @@ -124,6 +124,7 @@ private: TEST_CASE(template84); // #8880 TEST_CASE(template85); // #8902 crash TEST_CASE(template86); // crash + TEST_CASE(template87); TEST_CASE(template_specialization_1); // #7868 - template specialization template struct S> {..}; TEST_CASE(template_specialization_2); // #7868 - template specialization template struct S> {..}; TEST_CASE(template_enum); // #6299 Syntax error in complex enum declaration (including template) @@ -1651,6 +1652,18 @@ private: tok(code); } + void template87() { + const char code[] = "template\n" + "T f1(T t) { return t; }\n" + "template const char * f1();\n" + "template const char & f1();"; + const char exp[] = "const char * f1 ( const char * t ) ; " + "const char & f1 ( const char & t ) ; " + "const char * f1 ( const char * t ) { return t ; } " + "const char & f1 ( const char & t ) { return t ; }"; + ASSERT_EQUALS(exp, tok(code)); + } + void template_specialization_1() { // #7868 - template specialization template struct S> {..}; const char code[] = "template struct C {};\n" "template struct S {a};\n"