diff --git a/lib/astutils.cpp b/lib/astutils.cpp index e735a078f..a66bcf1bc 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -1506,8 +1506,12 @@ bool isSameExpression(bool cpp, bool macro, const Token *tok1, const Token *tok2 if (cpp) { if (tok1->str() == "." && tok1->astOperand1() && tok1->astOperand1()->str() == "this") tok1 = tok1->astOperand2(); + while (Token::simpleMatch(tok1, "::") && tok1->astOperand2()) + tok1 = tok1->astOperand2(); if (tok2->str() == "." && tok2->astOperand1() && tok2->astOperand1()->str() == "this") tok2 = tok2->astOperand2(); + while (Token::simpleMatch(tok2, "::") && tok2->astOperand2()) + tok2 = tok2->astOperand2(); } // Skip double not if (Token::simpleMatch(tok1, "!") && Token::simpleMatch(tok1->astOperand1(), "!") && !Token::simpleMatch(tok1->astParent(), "=") && astIsBoolLike(tok2)) { diff --git a/test/testother.cpp b/test/testother.cpp index b3d0fc0d2..6715ce90b 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -6875,6 +6875,31 @@ private: "[test.cpp:4]: (style) The comparison 'E0 > 0' is always false.\n" "[test.cpp:5]: (style) The comparison 'E0 == 0' is always true.\n", errout.str()); + + check("struct S {\n" // #12040, #12044 + " static const int I = 0;\n" + " enum { E0 };\n" + " enum F { F0 };\n" + " void f() {\n" + " if (0 > I) {}\n" + " if (0 > S::I) {}\n" + " if (0 > E0) {}\n" + " if (0 > S::E0) {}\n" + " }\n" + "};\n" + "void g() {\n" + " if (0 > S::I) {}\n" + " if (0 > S::E0) {}\n" + " if (0 > S::F::F0) {}\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:6]: (style) The comparison '0 > I' is always false.\n" + "[test.cpp:2] -> [test.cpp:7]: (style) The comparison '0 > S::I' is always false.\n" + "[test.cpp:8]: (style) The comparison '0 > E0' is always false.\n" + "[test.cpp:9]: (style) The comparison '0 > S::E0' is always false.\n" + "[test.cpp:2] -> [test.cpp:13]: (style) The comparison '0 > S::I' is always false.\n" + "[test.cpp:14]: (style) The comparison '0 > S::E0' is always false.\n" + "[test.cpp:15]: (style) The comparison '0 > S::F::F0' is always false.\n", + errout.str()); } void duplicateExpressionLoop() {