Skip to content

Commit

Permalink
Fix #12471 FP incorrectLogicOperator, followVariables does not seem t…
Browse files Browse the repository at this point in the history
…o care about setter
  • Loading branch information
chrchr-github committed Feb 27, 2024
1 parent da518aa commit d9d7259
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/astutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
19 changes: 19 additions & 0 deletions test/testcondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit d9d7259

Please sign in to comment.