diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 2bb695933..107ad43c1 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -3791,8 +3791,10 @@ void TemplateSimplifier::simplifyTemplates( specializations, maxtime, expandedtemplates); - if (instantiated) + if (instantiated) { mInstantiatedTemplates.push_back(*iter1); + mTemplateNamePos.clear(); // positions might be invalid after instantiations + } } for (std::list::const_iterator it = mInstantiatedTemplates.begin(); it != mInstantiatedTemplates.end(); ++it) { diff --git a/test/testsimplifytemplate.cpp b/test/testsimplifytemplate.cpp index 561ba9d56..be25ac053 100644 --- a/test/testsimplifytemplate.cpp +++ b/test/testsimplifytemplate.cpp @@ -218,6 +218,7 @@ private: TEST_CASE(template173); // #10332 crash TEST_CASE(template174); // #10506 hang TEST_CASE(template175); // #10908 + TEST_CASE(template176); // #11146 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) @@ -4458,7 +4459,7 @@ private: ASSERT_EQUALS(exp, tok(code)); } - void template175() + void template175() // #10908 { const char code[] = "template T Get() {return value;}\n" "char f() { Get(); }\n"; @@ -4468,6 +4469,27 @@ private: ASSERT_EQUALS(exp, tok(code)); } + void template176() // #11146 don't crash + { + const char code[] = "struct a {\n" + " template class b {};\n" + "};\n" + "struct c {\n" + " template a::b d();\n" + " ;\n" + "};\n" + "template a::b c::d() {}\n" + "template <> class a::b c::d() { return {}; };\n"; + const char exp[] = "struct a { " + "class b c :: d ( ) ; " + "template < typename > class b { } ; " + "} ; " + "struct c { a :: b d ( ) ; } ; " + "class a :: b c :: d ( ) { return { } ; } ; " + "a :: b c :: d ( ) { }"; + 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"