diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 035042369..5aa87a9ee 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -2237,8 +2237,13 @@ void TemplateSimplifier::simplifyTemplates( Token * tok = it->token; tok->deleteNext(2); tok->deleteThis(); - } else + } else { + // remove forward declaration if found + auto it1 = mTemplateForwardDeclarationsMap.find(it->token); + if (it1 != mTemplateForwardDeclarationsMap.end()) + removeTemplate(it1->second); removeTemplate(it->token); + } mTemplateDeclarations.erase(decl); } } diff --git a/test/testsimplifytemplate.cpp b/test/testsimplifytemplate.cpp index 98adff213..db597be73 100644 --- a/test/testsimplifytemplate.cpp +++ b/test/testsimplifytemplate.cpp @@ -1843,30 +1843,18 @@ private: " A a2;\n" "}\n"; - const char wanted[] = "class A ; " - "class A ; " - "void f ( ) " - "{" - " A a1 ;" - " A a2 ; " - "} " - "class A " - "{ int ar [ 2 ] ; } ; " - "class A " - "{ int ar [ 3 ] ; } ;"; - const char current[] = "template < class T , int n = 3 > class A ; " - "class A ; " - "class A ; " - "void f ( ) " - "{" - " A a1 ;" - " A a2 ; " - "} " - "class A " - "{ int ar [ 2 ] ; } ; " - "class A " - "{ int ar [ 3 ] ; } ;"; - TODO_ASSERT_EQUALS(wanted, current, tok(code)); + const char exp[] = "class A ; " + "class A ; " + "void f ( ) " + "{" + " A a1 ;" + " A a2 ; " + "} " + "class A " + "{ int ar [ 2 ] ; } ; " + "class A " + "{ int ar [ 3 ] ; } ;"; + ASSERT_EQUALS(exp, tok(code)); } { const char code[] = "template class A;\n" @@ -1880,30 +1868,18 @@ private: " A a2;\n" "}\n"; - const char wanted[] = "class A ; " - "class A ; " - "void f ( ) " - "{" - " A a1 ;" - " A a2 ; " - "} " - "class A " - "{ int ar [ 2 ] ; } ; " - "class A " - "{ int ar [ 3 ] ; } ;"; - const char current[] = "template < class , int = 3 > class A ; " - "class A ; " - "class A ; " - "void f ( ) " - "{" - " A a1 ;" - " A a2 ; " - "} " - "class A " - "{ int ar [ 2 ] ; } ; " - "class A " - "{ int ar [ 3 ] ; } ;"; - TODO_ASSERT_EQUALS(wanted, current, tok(code)); + const char exp[] = "class A ; " + "class A ; " + "void f ( ) " + "{" + " A a1 ;" + " A a2 ; " + "} " + "class A " + "{ int ar [ 2 ] ; } ; " + "class A " + "{ int ar [ 3 ] ; } ;"; + ASSERT_EQUALS(exp, tok(code)); } } @@ -2291,7 +2267,6 @@ private: "void SomeFunction ( ) { } " "private: " "int TemplatedMethod ( int ) ; " - "template < typename T > T TemplatedMethod ( T ) ; " // this should be removed "} ; " "} int MyNamespace :: TestClass :: TemplatedMethod ( int t ) { return t ; }", tok(code)); }