template simplifier: also remove forward declarations when removing expanded templates (#1536)

This commit is contained in:
IOBYTE 2018-12-20 14:55:27 -05:00 committed by amai2012
parent becc6f112a
commit d528934139
2 changed files with 30 additions and 50 deletions

View File

@ -2237,8 +2237,13 @@ void TemplateSimplifier::simplifyTemplates(
Token * tok = it->token; Token * tok = it->token;
tok->deleteNext(2); tok->deleteNext(2);
tok->deleteThis(); 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); removeTemplate(it->token);
}
mTemplateDeclarations.erase(decl); mTemplateDeclarations.erase(decl);
} }
} }

View File

@ -1843,7 +1843,7 @@ private:
" A<int> a2;\n" " A<int> a2;\n"
"}\n"; "}\n";
const char wanted[] = "class A<int,2> ; " const char exp[] = "class A<int,2> ; "
"class A<int,3> ; " "class A<int,3> ; "
"void f ( ) " "void f ( ) "
"{" "{"
@ -1854,19 +1854,7 @@ private:
"{ int ar [ 2 ] ; } ; " "{ int ar [ 2 ] ; } ; "
"class A<int,3> " "class A<int,3> "
"{ int ar [ 3 ] ; } ;"; "{ int ar [ 3 ] ; } ;";
const char current[] = "template < class T , int n = 3 > class A ; " ASSERT_EQUALS(exp, tok(code));
"class A<int,2> ; "
"class A<int,3> ; "
"void f ( ) "
"{"
" A<int,2> a1 ;"
" A<int,3> a2 ; "
"} "
"class A<int,2> "
"{ int ar [ 2 ] ; } ; "
"class A<int,3> "
"{ int ar [ 3 ] ; } ;";
TODO_ASSERT_EQUALS(wanted, current, tok(code));
} }
{ {
const char code[] = "template <class, int = 3> class A;\n" const char code[] = "template <class, int = 3> class A;\n"
@ -1880,7 +1868,7 @@ private:
" A<int> a2;\n" " A<int> a2;\n"
"}\n"; "}\n";
const char wanted[] = "class A<int,2> ; " const char exp[] = "class A<int,2> ; "
"class A<int,3> ; " "class A<int,3> ; "
"void f ( ) " "void f ( ) "
"{" "{"
@ -1891,19 +1879,7 @@ private:
"{ int ar [ 2 ] ; } ; " "{ int ar [ 2 ] ; } ; "
"class A<int,3> " "class A<int,3> "
"{ int ar [ 3 ] ; } ;"; "{ int ar [ 3 ] ; } ;";
const char current[] = "template < class , int = 3 > class A ; " ASSERT_EQUALS(exp, tok(code));
"class A<int,2> ; "
"class A<int,3> ; "
"void f ( ) "
"{"
" A<int,2> a1 ;"
" A<int,3> a2 ; "
"} "
"class A<int,2> "
"{ int ar [ 2 ] ; } ; "
"class A<int,3> "
"{ int ar [ 3 ] ; } ;";
TODO_ASSERT_EQUALS(wanted, current, tok(code));
} }
} }
@ -2291,7 +2267,6 @@ private:
"void SomeFunction ( ) { } " "void SomeFunction ( ) { } "
"private: " "private: "
"int TemplatedMethod<int> ( int ) ; " "int TemplatedMethod<int> ( int ) ; "
"template < typename T > T TemplatedMethod ( T ) ; " // this should be removed
"} ; " "} ; "
"} int MyNamespace :: TestClass :: TemplatedMethod<int> ( int t ) { return t ; }", tok(code)); "} int MyNamespace :: TestClass :: TemplatedMethod<int> ( int t ) { return t ; }", tok(code));
} }