diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index bb6ab9bd0..bbb108773 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -1733,7 +1733,8 @@ bool TemplateSimplifier::matchSpecialization( } // No specialization matches. Return true if the declaration is not a specialization. - return Token::Match(templateDeclarationNameToken, "%name% !!<"); + return Token::Match(templateDeclarationNameToken, "%name% !!<") && + (templateDeclarationNameToken->str().find('<') == std::string::npos); } std::string TemplateSimplifier::getNewName( diff --git a/test/testsimplifytemplate.cpp b/test/testsimplifytemplate.cpp index 0fa3d3b96..4b977fb9d 100644 --- a/test/testsimplifytemplate.cpp +++ b/test/testsimplifytemplate.cpp @@ -129,6 +129,7 @@ private: TEST_CASE(template89); // #8917 TEST_CASE(template90); // crash TEST_CASE(template91); + TEST_CASE(template92); 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) @@ -1809,6 +1810,29 @@ private: } } + void template92() { + const char code[] = "template void foo(T const& t) { }\n" + "template<> void foo(double const& d) { }\n" + "template void foo(float const& f);\n" + "int main() {\n" + " foo(2);\n" + " foo(3.14);\n" + " foo(3.14f);\n" + "}"; + const char exp[] = "void foo ( const double & d ) ; " + "void foo ( const float & t ) ; " + "void foo ( const int & t ) ; " + "void foo ( const double & d ) { } " + "int main ( ) { " + "foo ( 2 ) ; " + "foo ( 3.14 ) ; " + "foo ( 3.14f ) ; " + "} " + "void foo ( const float & t ) { } " + "void foo ( const int & 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"