diff --git a/lib/astutils.cpp b/lib/astutils.cpp index 017ff134f78..60fd28e3b32 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -2942,8 +2942,9 @@ static const Token* findExpressionChangedImpl(const Token* expr, const Token* result = nullptr; findAstNode(expr, [&](const Token* tok) { if (exprDependsOnThis(tok)) { - result = findThisChanged(start, end, false, settings, cpp); - return true; + result = findThisChanged(start, end, /*indirect*/ 0, settings, cpp); + if (result) + return true; } bool global = false; if (tok->variable()) { diff --git a/test/testcondition.cpp b/test/testcondition.cpp index 72adc6fac04..5e792ce993e 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -70,6 +70,7 @@ class TestCondition : public TestFixture { TEST_CASE(incorrectLogicOperator14); TEST_CASE(incorrectLogicOperator15); TEST_CASE(incorrectLogicOperator16); // #10070 + TEST_CASE(incorrectLogicOperator17); TEST_CASE(secondAlwaysTrueFalseWhenFirstTrueError); TEST_CASE(incorrectLogicOp_condSwapping); TEST_CASE(testBug5895); @@ -1722,6 +1723,24 @@ class TestCondition : public TestFixture { ASSERT_EQUALS("", errout.str()); } + void incorrectLogicOperator17() { // #12471 + check("struct R {\n" + " void set() { i = 1; }\n" + " int get() const { return i; }\n" + " int i;\n" + "};\n" + "struct P {\n" + " void f();\n" + " R* r;\n" + "};\n" + "void P::f() {\n" + " int a = r->get();\n" + " r->set();\n" + " if (a == 0 && r->get()) {}\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + } + void secondAlwaysTrueFalseWhenFirstTrueError() { check("void f(void) {\n" // #8892 " const char c[1] = { \'x\' }; \n"