From 59f7b937f14bc16326a879b91b0f11e866a4c865 Mon Sep 17 00:00:00 2001 From: IOBYTE Date: Mon, 19 Apr 2021 03:17:49 -0400 Subject: [PATCH] fix daca2 gdcm template simplifier crash (#3221) This only fixes the crash. The templates that are instantiated are correct but one template is left uninstantiated. Fixing the missing instantiation is not easy and will be looked at later. Co-authored-by: Robert Reif --- lib/templatesimplifier.cpp | 2 +- test/testsimplifytemplate.cpp | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 1faf58e8b..a36798fa1 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -2928,7 +2928,7 @@ std::string TemplateSimplifier::getNewName( } if (Token::Match(tok3->tokAt(-2), "<|,|:: %name% <") && (tok3->strAt(1) == ">" || templateParameters(tok3))) ++indentlevel; - else if (indentlevel > 0 && Token::Match(tok3, "> [,>]")) + else if (indentlevel > 0 && Token::Match(tok3, "> ,|>|::")) --indentlevel; if (indentlevel == 0 && Token::Match(tok3->previous(), "[<,]")) { mTypesUsedInTemplateInstantiation.emplace_back(tok3, ""); diff --git a/test/testsimplifytemplate.cpp b/test/testsimplifytemplate.cpp index f50687c79..858e61316 100644 --- a/test/testsimplifytemplate.cpp +++ b/test/testsimplifytemplate.cpp @@ -212,6 +212,7 @@ private: TEST_CASE(template168); TEST_CASE(template169); TEST_CASE(template170); // crash + TEST_CASE(template171); // crash 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) @@ -4368,6 +4369,27 @@ private: ASSERT_EQUALS(exp, tok(code)); } + void template171() { // crash + const char code[] = "template struct c { enum { b }; };\n" + "template struct h { enum { d }; enum { e }; };\n" + "template ::d, int g = h::e> class i { enum { e = c::b }; };\n" + "void j() { i<2> a; }"; + const char exp[] = "struct c::e> ; " + "struct h<2> ; " + "class i<2,h<2>::d,h<2>::e> ; " + "void j ( ) { i<2,h<2>::d,h<2>::e> a ; } " + "class i<2,h<2>::d,h<2>::e> { enum Anonymous3 { e = c::e> :: b } ; } ; " + "struct h<2> { enum Anonymous1 { d } ; enum Anonymous2 { e } ; } ; " + "struct c::e> { enum Anonymous0 { b } ; } ;"; + const char act[] = "struct c::e> ; " + "template < int > struct h { enum Anonymous1 { d } ; enum Anonymous2 { e } ; } ; " + "class i<2,h<2>::d,h<2>::e> ; " + "void j ( ) { i<2,h<2>::d,h<2>::e> a ; } " + "class i<2,h<2>::d,h<2>::e> { enum Anonymous3 { e = c::e> :: b } ; } ; " + "struct c::e> { enum Anonymous0 { b } ; } ;"; + TODO_ASSERT_EQUALS(exp, act, tok(code)); + } + void template_specialization_1() { // #7868 - template specialization template struct S> {..}; const char code[] = "template struct C {};\n" "template struct S {a};\n"