From ef0a7d61d6ab3c68509578382cc28709f5d50fdd Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 28 Feb 2024 16:16:29 +0100 Subject: [PATCH] Fix #12471 FP incorrectLogicOperator, followVariables does not seem to care about setter (#6051) --- lib/astutils.cpp | 5 +++-- test/testcondition.cpp | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/astutils.cpp b/lib/astutils.cpp index 13996d0b965..70cc971ca15 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"