diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 478dca9ae..2b97893cf 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -1092,17 +1092,19 @@ bool TemplateSimplifier::simplifyTemplateInstantiations( else if (indentlevel > 0 && Token::Match(tok3, "> [,>]")) --indentlevel; templateMatchPattern += tok3->str(); - templateMatchPattern += " "; + templateMatchPattern += ' '; if (indentlevel == 0 && Token::Match(tok3->previous(), "[<,]")) typesUsedInTemplateInstantiation.push_back(tok3); // add additional type information - if (tok3->isUnsigned()) - typeForNewNameStr += "unsigned"; - else if (tok3->isSigned()) - typeForNewNameStr += "signed"; - if (tok3->isLong()) - typeForNewNameStr += "long"; - typeForNewNameStr += tok3->str(); + if (tok3->str() != "class") { + if (tok3->isUnsigned()) + typeForNewNameStr += "unsigned"; + else if (tok3->isSigned()) + typeForNewNameStr += "signed"; + if (tok3->isLong()) + typeForNewNameStr += "long"; + typeForNewNameStr += tok3->str(); + } } templateMatchPattern += ">"; const std::string typeForNewName(typeForNewNameStr); diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 78b42781b..9c5c2c8fb 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -128,6 +128,7 @@ private: TEST_CASE(template34); // #3706 - namespace => hang TEST_CASE(template35); // #4074 - A<'x'> a; TEST_CASE(template36); // #4310 - passing unknown template instantiation as template argument + TEST_CASE(template37); // #4544 - A a; TEST_CASE(template_unhandled); TEST_CASE(template_default_parameter); TEST_CASE(template_default_type); @@ -2252,6 +2253,15 @@ private: tok(code)); } + void template37() { // #4544 - A a; + const char code[] = "class A { };\n" + "template class B {};\n" + "B b1;\n" + "B b2;"; + ASSERT_EQUALS("class A { } ; B b1 ; B b2 ; class B { }", + tok(code)); + } + void template_unhandled() { // An unhandled template usage should be simplified.. ASSERT_EQUALS("x ( ) ;", tok("x();"));