From a52ce7379aa69cffdcf796093398ea84ad7e1921 Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Thu, 10 Sep 2020 14:47:59 -0400 Subject: [PATCH] fix #9886 (Hang in TemplateSimplifier (gcc/gcc/testsuite/g++.dg/cpp0x/decltype34.C)) --- lib/templatesimplifier.cpp | 2 +- test/testsimplifytemplate.cpp | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) 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"