diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 0dab6b681..f87f94114 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -1127,7 +1127,7 @@ void TemplateSimplifier::useDefaultArgumentValues(TokenAndName &declaration) (from->strAt(1) == ">" || (from->previous()->isName() && typeParameterNames.find(from->strAt(-1)) == typeParameterNames.end()))) ++indentlevel; - else if (from->str() == ">" && (links.empty() || links.top()->str() == "<")) + else if (from->str() == ">" && (links.empty() || links.top()->str() == "<" || indentlevel)) --indentlevel; auto entry = typeParameterNames.find(from->str()); if (entry != typeParameterNames.end() && entry->second < instantiationArgs.size()) { diff --git a/test/testsimplifytemplate.cpp b/test/testsimplifytemplate.cpp index b42a4ddfa..d84211abc 100644 --- a/test/testsimplifytemplate.cpp +++ b/test/testsimplifytemplate.cpp @@ -198,6 +198,7 @@ private: TEST_CASE(template156); TEST_CASE(template157); // #9854 TEST_CASE(template158); // daca crash + TEST_CASE(template159); // #9886 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) @@ -4018,6 +4019,24 @@ private: tok(code); // don't crash } + void template159() { // #9886 + const char code[] = "struct impl { template static T create(); };\n" + "template()->impl::create())>\n" + "struct tester{};\n" + "tester ti;\n" + "template()->impl::create())>\n" + "int test() { return 0; }\n" + "int i = test();"; + const char exp[] = "struct impl { template < class T > static T create ( ) ; } ; " + "struct tester().impl::create())> ; " + "tester().impl::create())> ti ; " + "int test().impl::create())> ( ) ; " + "int i ; i = test().impl::create())> ( ) ; " + "int test().impl::create())> ( ) { return 0 ; } " + "struct tester().impl::create())> { } ;"; + 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"