diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 231978e82..cd768fd09 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -1763,7 +1763,7 @@ void TemplateSimplifier::expandTemplate( } } else if (copy) { bool added = false; - if (tok5->isName()) { + if (tok5->isName() && !Token::Match(tok5, "class|typename|struct")) { // search for this token in the type vector unsigned int itype = 0; while (itype < typeParametersInDeclaration.size() && typeParametersInDeclaration[itype]->str() != tok5->str()) @@ -1838,9 +1838,8 @@ void TemplateSimplifier::expandTemplate( // FIXME use full name matching somehow const std::string lastName = (templateInstantiation.name.find(' ') != std::string::npos) ? templateInstantiation.name.substr(templateInstantiation.name.rfind(' ')+1) : templateInstantiation.name; - for (; tok3; tok3 = tok3->next()) { - if (tok3->isName()) { + if (tok3->isName() && !Token::Match(tok3, "class|typename|struct")) { // search for this token in the type vector unsigned int itype = 0; while (itype < typeParametersInDeclaration.size() && typeParametersInDeclaration[itype]->str() != tok3->str()) diff --git a/test/testsimplifytemplate.cpp b/test/testsimplifytemplate.cpp index 874a278b2..6f5daaaec 100644 --- a/test/testsimplifytemplate.cpp +++ b/test/testsimplifytemplate.cpp @@ -150,6 +150,7 @@ private: TEST_CASE(template110); TEST_CASE(template111); // crash TEST_CASE(template112); // #9146 syntax error + TEST_CASE(template113); 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) @@ -2642,6 +2643,25 @@ private: ASSERT_EQUALS(exp, tok(code)); } + void template113() { + { + const char code[] = "template class A { void f(); };\n" + "A a;"; + const char exp[] = "class A ; " + "A a ; " + "class A { void f ( ) ; } ;"; + ASSERT_EQUALS(exp, tok(code)); + } + { + const char code[] = "template struct A { void f(); };\n" + "A a;"; + const char exp[] = "struct A ; " + "A a ; " + "struct A { void f ( ) ; } ;"; + 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"