diff --git a/lib/astutils.cpp b/lib/astutils.cpp index c648e79a5b2..8c87b324127 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -1615,10 +1615,14 @@ 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(followTok2, "::") && followTok2->astOperand2()) - followTok2 = followTok2->astOperand2(); + 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; 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() {