From 15560c04d5f6a8c796271ab0310fc2b36a72246a Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Sun, 30 Mar 2025 01:51:28 +0100 Subject: [PATCH 1/8] Partial fix for #13747 assertion in Token::update_property_info() --- lib/templatesimplifier.cpp | 2 +- test/testsimplifytemplate.cpp | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 2a8575c2a46..57b3f0b4b5d 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -2080,7 +2080,7 @@ void TemplateSimplifier::expandTemplate( --scopeCount; if (scopeCount < 0) break; - if (tok3->isName() && !Token::Match(tok3, "class|typename|struct") && !tok3->isStandardType()) { + if (tok3->isName() && !Token::Match(tok3, "class|typename|struct") && !tok3->isStandardType() && !Token::simpleMatch(tok3->previous(), ".")) { // search for this token in the type vector unsigned int itype = 0; while (itype < typeParametersInDeclaration.size() && typeParametersInDeclaration[itype]->str() != tok3->str()) diff --git a/test/testsimplifytemplate.cpp b/test/testsimplifytemplate.cpp index 155dd0aa9a8..808d26aaf4c 100644 --- a/test/testsimplifytemplate.cpp +++ b/test/testsimplifytemplate.cpp @@ -217,6 +217,7 @@ class TestSimplifyTemplate : public TestFixture { TEST_CASE(template178); TEST_CASE(template179); TEST_CASE(template180); + TEST_CASE(template181); 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); @@ -4593,6 +4594,26 @@ class TestSimplifyTemplate : public TestFixture { ASSERT_EQUALS(exp, tok(code)); } + void template181() { + const char code[] = "struct K { bool b; };\n" + "template\n" + "void f(struct K* k) {\n" + " assert(b == k->b);\n" + "}\n" + "void g(struct K* k) {\n" + " f(k);\n" + "}\n"; + const char exp[] = "struct K { bool b ; } ; " + "void f ( struct K * k ) ; " + "void g ( struct K * k ) { " + "f ( k ) ; " + "} " + "void f ( struct K * k ) { " + "assert ( false == k . b ) ; " + "}"; + 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" From 25403f820b43474354ef19f91d2cd913dd1c34ae Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 9 Apr 2025 08:15:11 +0200 Subject: [PATCH 2/8] Update templatesimplifier.cpp --- lib/templatesimplifier.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 57b3f0b4b5d..17bbef6e94a 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -12,7 +12,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License + * You should have received a copy of the GNU General Public Licensef * along with this program. If not, see . */ @@ -2080,7 +2080,7 @@ void TemplateSimplifier::expandTemplate( --scopeCount; if (scopeCount < 0) break; - if (tok3->isName() && !Token::Match(tok3, "class|typename|struct") && !tok3->isStandardType() && !Token::simpleMatch(tok3->previous(), ".")) { + if (tok3->isName() && !Token::Match(tok3, "class|typename|struct") && !tok3->isStandardType() && !Token::Match(tok3->previous(), ".|::")) { // search for this token in the type vector unsigned int itype = 0; while (itype < typeParametersInDeclaration.size() && typeParametersInDeclaration[itype]->str() != tok3->str()) From 2f2f45c80ef52585d6c403bbb2f73a0a5e346e8e Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 9 Apr 2025 09:02:42 +0200 Subject: [PATCH 3/8] Update testsimplifytemplate.cpp --- test/testsimplifytemplate.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/testsimplifytemplate.cpp b/test/testsimplifytemplate.cpp index 808d26aaf4c..f88d7aae098 100644 --- a/test/testsimplifytemplate.cpp +++ b/test/testsimplifytemplate.cpp @@ -3712,7 +3712,7 @@ class TestSimplifyTemplate : public TestFixture { "class GenericConfigurationHandler ; " "class TargetConfigurationHandler : public GenericConfigurationHandler { } ; " "class GenericConfigurationHandler { " - "std :: list < int , std :: std :: allocator < int > > m_target_configurations ; " + "std :: list < int , std :: allocator < int > > m_target_configurations ; " "} ;"; ASSERT_EQUALS(exp, tok(code)); } From 5a05b4fcac44081a9350c8631219e5e2ca547ff5 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 9 Apr 2025 11:45:02 +0200 Subject: [PATCH 4/8] Update templatesimplifier.cpp --- lib/templatesimplifier.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 17bbef6e94a..c6ec6051a17 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -12,7 +12,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public Licensef + * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ From c66e0ac45e676b1b39be61f850339b35ee79eb00 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 9 Apr 2025 11:50:19 +0200 Subject: [PATCH 5/8] Update testsimplifytemplate.cpp --- test/testsimplifytemplate.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/test/testsimplifytemplate.cpp b/test/testsimplifytemplate.cpp index f88d7aae098..cf40dbc0a8e 100644 --- a/test/testsimplifytemplate.cpp +++ b/test/testsimplifytemplate.cpp @@ -4595,7 +4595,7 @@ class TestSimplifyTemplate : public TestFixture { } void template181() { - const char code[] = "struct K { bool b; };\n" + const char code[] = "struct K { bool b; };\n" // #13747 "template\n" "void f(struct K* k) {\n" " assert(b == k->b);\n" @@ -4612,6 +4612,24 @@ class TestSimplifyTemplate : public TestFixture { "assert ( false == k . b ) ; " "}"; ASSERT_EQUALS(exp, tok(code)); + + const char code2[] = "namespace N { bool b = false; }\n" + "template\n" + "void f() {\n" + " assert(b == N::b);\n" + "}\n" + "void g() {\n" + " f(); + "}\n"; + const char exp2[] = "namespace N { bool b ; b = false ; } ; " + "void f ( ) ; " + "void g ( ) { " + "f ( ) ; " + "} " + "void f ( ) { " + "assert ( false == N :: b ) ; " + "}"; + ASSERT_EQUALS(exp2, tok(code2)); } void template_specialization_1() { // #7868 - template specialization template struct S> {..}; From 02ce9fef3609c70db1ed37dd899f75ee98d3ad5e Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 9 Apr 2025 11:52:03 +0200 Subject: [PATCH 6/8] Update testsimplifytemplate.cpp --- test/testsimplifytemplate.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/testsimplifytemplate.cpp b/test/testsimplifytemplate.cpp index cf40dbc0a8e..1bcc4a59ebf 100644 --- a/test/testsimplifytemplate.cpp +++ b/test/testsimplifytemplate.cpp @@ -4613,14 +4613,14 @@ class TestSimplifyTemplate : public TestFixture { "}"; ASSERT_EQUALS(exp, tok(code)); - const char code2[] = "namespace N { bool b = false; }\n" + const char code2[] = "namespace N { bool b = false; }\n" // #13759 "template\n" "void f() {\n" - " assert(b == N::b);\n" + " assert(b == N::b);\n" "}\n" "void g() {\n" - " f(); - "}\n"; + " f(); + "}\n"; const char exp2[] = "namespace N { bool b ; b = false ; } ; " "void f ( ) ; " "void g ( ) { " From ba41caf3631917ea527b7c4409f0a29188510c5b Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 9 Apr 2025 11:54:30 +0200 Subject: [PATCH 7/8] Update testsimplifytemplate.cpp --- test/testsimplifytemplate.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/testsimplifytemplate.cpp b/test/testsimplifytemplate.cpp index 1bcc4a59ebf..1001cb2f27a 100644 --- a/test/testsimplifytemplate.cpp +++ b/test/testsimplifytemplate.cpp @@ -4619,7 +4619,7 @@ class TestSimplifyTemplate : public TestFixture { " assert(b == N::b);\n" "}\n" "void g() {\n" - " f(); + " f();\n" "}\n"; const char exp2[] = "namespace N { bool b ; b = false ; } ; " "void f ( ) ; " From d2bc11071109f4c1290bf95524b8afccfd5b4659 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 9 Apr 2025 12:03:46 +0200 Subject: [PATCH 8/8] Update testsimplifytemplate.cpp --- test/testsimplifytemplate.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/testsimplifytemplate.cpp b/test/testsimplifytemplate.cpp index 1001cb2f27a..495b65ca38f 100644 --- a/test/testsimplifytemplate.cpp +++ b/test/testsimplifytemplate.cpp @@ -4616,12 +4616,12 @@ class TestSimplifyTemplate : public TestFixture { const char code2[] = "namespace N { bool b = false; }\n" // #13759 "template\n" "void f() {\n" - " assert(b == N::b);\n" + " assert(b == N::b);\n" "}\n" "void g() {\n" - " f();\n" + " f();\n" "}\n"; - const char exp2[] = "namespace N { bool b ; b = false ; } ; " + const char exp2[] = "namespace N { bool b ; b = false ; } " "void f ( ) ; " "void g ( ) { " "f ( ) ; "