Skip to content

Commit 98b6ff5

Browse files
Fix #14234 FN selfAssignment with global scope operator (#7934)
1 parent 828e903 commit 98b6ff5

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

lib/astutils.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1615,10 +1615,14 @@ bool isSameExpression(bool macro, const Token *tok1, const Token *tok2, const Se
16151615
return false;
16161616

16171617
const Token *followTok1 = tok1, *followTok2 = tok2;
1618-
while (Token::simpleMatch(followTok1, "::") && followTok1->astOperand2())
1619-
followTok1 = followTok1->astOperand2();
1620-
while (Token::simpleMatch(followTok2, "::") && followTok2->astOperand2())
1621-
followTok2 = followTok2->astOperand2();
1618+
while (Token::simpleMatch(followTok1, "::"))
1619+
followTok1 = followTok1->astOperand2() ? followTok1->astOperand2() : followTok1->astOperand1();
1620+
if (!followTok1)
1621+
followTok1 = tok1; // TODO: remove after #14235 has been fixed
1622+
while (Token::simpleMatch(followTok2, "::"))
1623+
followTok2 = followTok2->astOperand2() ? followTok2->astOperand2() : followTok2->astOperand1();
1624+
if (!followTok2)
1625+
followTok2 = tok2;
16221626
if (isSameConstantValue(macro, followTok1, followTok2))
16231627
return true;
16241628

test/testother.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6401,6 +6401,10 @@ class TestOther : public TestFixture {
64016401
" s.i = o;\n"
64026402
"}\n");
64036403
ASSERT_EQUALS("", errout_str());
6404+
6405+
check("int N;\n" // #14234
6406+
"void f() { ::N = N; }\n");
6407+
ASSERT_EQUALS("[test.cpp:2:16]: (style) Redundant assignment of '::N' to itself. [selfAssignment]\n", errout_str());
64046408
}
64056409

64066410
void trac1132() {

0 commit comments

Comments
 (0)