diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 1aad8738e..c721974f1 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -1249,12 +1249,15 @@ bool TemplateSimplifier::simplifyTemplateInstantiations( ++indentlevel; else if (indentlevel > 0 && Token::Match(tok3, "> [,>]")) --indentlevel; - templateMatchPattern += tok3->str(); - templateMatchPattern += ' '; + bool constconst = tok3->str() == "const" && tok3->strAt(1) == "const"; + if (!constconst) { + templateMatchPattern += tok3->str(); + templateMatchPattern += ' '; + } if (indentlevel == 0 && Token::Match(tok3->previous(), "[<,]")) typesUsedInTemplateInstantiation.push_back(tok3); // add additional type information - if (tok3->str() != "class") { + if (!constconst && tok3->str() != "class") { if (tok3->isUnsigned()) typeForNewNameStr += "unsigned"; else if (tok3->isSigned()) diff --git a/test/testsimplifytemplate.cpp b/test/testsimplifytemplate.cpp index 41c5a04af..6b553a167 100644 --- a/test/testsimplifytemplate.cpp +++ b/test/testsimplifytemplate.cpp @@ -85,6 +85,7 @@ private: TEST_CASE(template52); // #6437 - crash upon valid code TEST_CASE(template53); // #4335 - bail out for valid code TEST_CASE(template54); // #6587 - memory corruption upon valid code + TEST_CASE(template55); // #6604 - simplify "const const" to "const" in template instantiations TEST_CASE(template_unhandled); TEST_CASE(template_default_parameter); TEST_CASE(template_default_type); @@ -961,6 +962,22 @@ private: "A a;"); } + void template55() { // #6604 + ASSERT_EQUALS( + "class AtSmartPtr : public ConstCastHelper < AtSmartPtr , T > { " + "friend struct ConstCastHelper < AtSmartPtr , T > ; " + "AtSmartPtr ( const AtSmartPtr & r ) ; " + "} ; " + "class AtSmartPtr : public ConstCastHelper < AtSmartPtr < const const T > , const T > { " + "friend struct ConstCastHelper < AtSmartPtr < const const T > , const T > ; " + "AtSmartPtr ( const AtSmartPtr & r ) ; } ;", + tok("template class AtSmartPtr : public ConstCastHelper, T>\n" + "{\n" + " friend struct ConstCastHelper, T>;\n" + " AtSmartPtr(const AtSmartPtr& r);\n" + "};")); + } + void template_default_parameter() { { const char code[] = "template \n"