From 4779f0e1725c5807b329798e12dbeaddbf568b65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 1 Sep 2022 20:24:01 +0200 Subject: [PATCH] TemplateSimplifier: Fixed instantiation when template parameters are A<..>, B<..> --- lib/templatesimplifier.cpp | 2 +- test/testsimplifytemplate.cpp | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 02a021d21..83f51b22a 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -2966,7 +2966,7 @@ std::string TemplateSimplifier::getNewName( ++indentlevel; else if (indentlevel > 0 && Token::Match(tok3, "> ,|>|::")) --indentlevel; - if (indentlevel == 0 && Token::Match(tok3->previous(), "[<,]")) { + else if (indentlevel == 0 && Token::Match(tok3->previous(), "[<,]")) { mTypesUsedInTemplateInstantiation.emplace_back(tok3, ""); } if (Token::Match(tok3, "(|[")) diff --git a/test/testsimplifytemplate.cpp b/test/testsimplifytemplate.cpp index 53a366d1a..52c4f58f9 100644 --- a/test/testsimplifytemplate.cpp +++ b/test/testsimplifytemplate.cpp @@ -220,6 +220,7 @@ private: TEST_CASE(template174); // #10506 hang TEST_CASE(template175); // #10908 TEST_CASE(template176); // #11146 + TEST_CASE(template177); 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) @@ -4491,6 +4492,16 @@ private: ASSERT_EQUALS(exp, tok(code)); } + void template177() { + const char code[] = "template \n" + "class C { xyz x; };\n" + "C, MemoryPoolAllocator<>> c;"; + const char exp[] = "class C,MemoryPoolAllocator<>> ; " + "C,MemoryPoolAllocator<>> c ; " + "class C,MemoryPoolAllocator<>> { xyz < UTF8 < > , MemoryPoolAllocator < > > x ; } ;"; + 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"