diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 9a2b7188d..5f444113c 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -575,7 +575,9 @@ void TemplateSimplifier::getTemplateInstantiations() if (Token::Match(tok2, ", %name% <") && templateParameters(tok2->tokAt(2))) { mTemplateInstantiations.emplace_back(tok2->next(), getScopeName(scopeList), tok2->strAt(1)); - } + } else if (Token::Match(tok2->next(), "class|struct")) + const_cast(tok2)->deleteNext(); + } // Add outer template.. diff --git a/test/testsimplifytemplate.cpp b/test/testsimplifytemplate.cpp index fb8b71f8a..2e30971a4 100644 --- a/test/testsimplifytemplate.cpp +++ b/test/testsimplifytemplate.cpp @@ -108,6 +108,7 @@ private: TEST_CASE(template68); // union TEST_CASE(template69); // #8791 TEST_CASE(template70); // #5289 + TEST_CASE(template71); // #8821 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) @@ -1296,6 +1297,27 @@ private: ASSERT_EQUALS(exp, tok(code)); } + void template71() { // #8821 + const char code[] = "int f1(int * pInterface, int x) { return 0; }\n" + "\n" + "template< class interface_type > class Reference {\n" + " template< class interface_type > int i();\n" + " int *pInterface;\n" + "};\n" + "\n" + "template< class interface_type > int Reference< interface_type >::i() {\n" + " return f1(pInterface, interface_type::static_type());\n" + "}\n" + "\n" + "Reference< class XPropertyList > dostuff();"; + const char exp [] = "int f1 ( int * pInterface , int x ) { return 0 ; } " + "class Reference ; " + "Reference dostuff ( ) ; " + "class Reference { template < class XPropertyList > int i ( ) ; int * pInterface ; } ; " + "int Reference :: i ( ) { return f1 ( pInterface , XPropertyList :: static_type ( ) ) ; }"; + 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"