From 1ef66adf55d0108daa7f2417ef21e3b0d44e64b9 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 30 Oct 2025 09:30:52 +0100 Subject: [PATCH 1/4] Update astutils.cpp --- lib/astutils.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/astutils.cpp b/lib/astutils.cpp index c648e79a5b2..f7addf91861 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -1615,10 +1615,10 @@ bool isSameExpression(bool macro, const Token *tok1, const Token *tok2, const Se return false; const Token *followTok1 = tok1, *followTok2 = tok2; - while (Token::simpleMatch(followTok1, "::") && followTok1->astOperand2()) - followTok1 = followTok1->astOperand2(); + while (Token::simpleMatch(followTok1, "::")) + followTok1 = followTok1->astOperand2() ? followTok1->astOperand2() : followTok1->astOperand1(); while (Token::simpleMatch(followTok2, "::") && followTok2->astOperand2()) - followTok2 = followTok2->astOperand2(); + followTok2 = followTok2->astOperand2() ? followTok2->astOperand2() : followTok2->astOperand1(); if (isSameConstantValue(macro, followTok1, followTok2)) return true; From 848a003c2a8d20d71ca203ce432876470c5b2fe4 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 30 Oct 2025 09:32:12 +0100 Subject: [PATCH 2/4] Update testother.cpp --- test/testother.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/testother.cpp b/test/testother.cpp index d1fc966d6ff..5aaa0b53c14 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -6401,6 +6401,10 @@ class TestOther : public TestFixture { " s.i = o;\n" "}\n"); ASSERT_EQUALS("", errout_str()); + + check("int N;\n" // #14234 + "void f() { ::N = N; }\n"); + ASSERT_EQUALS("[test.cpp:2:16]: (style) Redundant assignment of '::N' to itself. [selfAssignment]\n", errout_str()); } void trac1132() { From 0492781f8577e4bc558bf2febdb448a3b07a7255 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 30 Oct 2025 11:30:37 +0100 Subject: [PATCH 3/4] Update astutils.cpp --- lib/astutils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/astutils.cpp b/lib/astutils.cpp index f7addf91861..b3d37509af2 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -1617,7 +1617,7 @@ bool isSameExpression(bool macro, const Token *tok1, const Token *tok2, const Se const Token *followTok1 = tok1, *followTok2 = tok2; while (Token::simpleMatch(followTok1, "::")) followTok1 = followTok1->astOperand2() ? followTok1->astOperand2() : followTok1->astOperand1(); - while (Token::simpleMatch(followTok2, "::") && followTok2->astOperand2()) + while (Token::simpleMatch(followTok2, "::")) followTok2 = followTok2->astOperand2() ? followTok2->astOperand2() : followTok2->astOperand1(); if (isSameConstantValue(macro, followTok1, followTok2)) return true; From 754640ae0c7b7debf2894bed1b9d4d51cda63077 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 30 Oct 2025 12:43:20 +0100 Subject: [PATCH 4/4] Update astutils.cpp --- lib/astutils.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/astutils.cpp b/lib/astutils.cpp index b3d37509af2..8c87b324127 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -1617,8 +1617,12 @@ bool isSameExpression(bool macro, const Token *tok1, const Token *tok2, const Se const Token *followTok1 = tok1, *followTok2 = tok2; while (Token::simpleMatch(followTok1, "::")) followTok1 = followTok1->astOperand2() ? followTok1->astOperand2() : followTok1->astOperand1(); + if (!followTok1) + followTok1 = tok1; // TODO: remove after #14235 has been fixed while (Token::simpleMatch(followTok2, "::")) followTok2 = followTok2->astOperand2() ? followTok2->astOperand2() : followTok2->astOperand1(); + if (!followTok2) + followTok2 = tok2; if (isSameConstantValue(macro, followTok1, followTok2)) return true;