From c1af70b2fc658118ad6ceff9af4658e528d8d5bc Mon Sep 17 00:00:00 2001 From: chrchr Date: Thu, 21 Mar 2024 10:40:13 +0100 Subject: [PATCH 1/2] Fix #12312 FP variableScope with templates in namespace --- 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 943779b7b7f..d02f135d1ed 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -2172,7 +2172,7 @@ void TemplateSimplifier::expandTemplate( addNamespace(templateDeclaration, tok3); } mTokenList.addtoken(newName, tok3); - } else if (!Token::Match(tok3->next(), ":|{|=|;|[|]")) + } else if (!Token::Match(tok3->next(), "[:{=;[]),]")) tok3->str(newName); continue; } diff --git a/test/testsimplifytemplate.cpp b/test/testsimplifytemplate.cpp index e7722dcf90c..f9ef4500066 100644 --- a/test/testsimplifytemplate.cpp +++ b/test/testsimplifytemplate.cpp @@ -219,6 +219,7 @@ class TestSimplifyTemplate : public TestFixture { TEST_CASE(template178); 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); TEST_CASE(template_enum); // #6299 Syntax error in complex enum declaration (including template) TEST_CASE(template_unhandled); TEST_CASE(template_default_parameter); @@ -4562,6 +4563,24 @@ class TestSimplifyTemplate : public TestFixture { "S> s;"; const char exp[] = "template < typename T > struct C { } ; template < typename T > struct S { a } ; struct S> ; S> s ; struct S> { b } ;"; ASSERT_EQUALS(exp, tok(code)); + } + + void template_specialization_3() { + const char code[] = "namespace N {\n" // #12312 + " template \n" + " bool equal(const T&);\n" + " template <>\n" + " bool equal(const int&) { return false; }\n" + "}\n" + "void f(bool equal, int i) { if (equal) {} }\n"; + const char exp[] = "namespace N { " + "bool equal ( const int & ) ; " + "template < typename T > " + "bool equal ( const T & ) ; " + "bool equal ( const int & ) { return false ; } " + "} " + "void f ( bool equal , int i ) { if ( equal ) { } }"; + ASSERT_EQUALS(exp, tok(code)); } void template_enum() { From f26776f8bc84b112f36df26b5fccc1417b1d7425 Mon Sep 17 00:00:00 2001 From: chrchr Date: Thu, 21 Mar 2024 10:51:34 +0100 Subject: [PATCH 2/2] Format --- test/testsimplifytemplate.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/testsimplifytemplate.cpp b/test/testsimplifytemplate.cpp index f9ef4500066..56644cb4396 100644 --- a/test/testsimplifytemplate.cpp +++ b/test/testsimplifytemplate.cpp @@ -4563,7 +4563,7 @@ class TestSimplifyTemplate : public TestFixture { "S> s;"; const char exp[] = "template < typename T > struct C { } ; template < typename T > struct S { a } ; struct S> ; S> s ; struct S> { b } ;"; ASSERT_EQUALS(exp, tok(code)); - } + } void template_specialization_3() { const char code[] = "namespace N {\n" // #12312