diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index d73b3e7a9aa..1fe1df10037 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -2085,8 +2085,11 @@ void TemplateSimplifier::expandTemplate( std::stack templates; int scopeCount = 0; for (; tok3; tok3 = tok3->next()) { - if (tok3->str() == "{") + if (tok3->str() == "{") { + if (isFunction && isSpecialization && inTemplateDefinition) + break; ++scopeCount; + } else if (tok3->str() == "}") --scopeCount; if (scopeCount < 0) diff --git a/test/testsimplifytemplate.cpp b/test/testsimplifytemplate.cpp index 66b2e022679..b28bc503869 100644 --- a/test/testsimplifytemplate.cpp +++ b/test/testsimplifytemplate.cpp @@ -225,6 +225,7 @@ class TestSimplifyTemplate : public TestFixture { TEST_CASE(template181); TEST_CASE(template182); // #13770 TEST_CASE(template183); + TEST_CASE(template184); 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_specialization_3); @@ -4698,6 +4699,32 @@ class TestSimplifyTemplate : public TestFixture { ASSERT_EQUALS(exp, tok(code)); } + void template184() { + const char code[] = "template \n" + "T g(T x) {\n" + " return x;\n" + "}\n" + "template <>\n" + "float g(float x) {\n" + " return x + 1.0f;\n" + "}\n" + "void f(int i) {\n" + " g(i);\n" + " g(1.0f);\n" + "}\n"; + const char exp[] = "float g ( float x ) ; " + "template < typename T > " + "T g ( T x ) { return x ; } " + "float g ( float x ) {" + " return x + 1.0f ; " + "} " + "void f ( int i ) {" + " g ( i ) ;" + " g ( 1.0f ) ; " + "}"; + ASSERT_EQUALS(exp, tok(code)); // TODO: instantiate g(int) + } + void template_specialization_1() { // #7868 - template specialization template struct S> {..}; const char code[] = "template struct C {};\n" "template struct S {a};\n"