Skip to content

Commit ef0a7d6

Browse files
Fix #12471 FP incorrectLogicOperator, followVariables does not seem to care about setter (#6051)
1 parent 5da25c1 commit ef0a7d6

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

lib/astutils.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2942,8 +2942,9 @@ static const Token* findExpressionChangedImpl(const Token* expr,
29422942
const Token* result = nullptr;
29432943
findAstNode(expr, [&](const Token* tok) {
29442944
if (exprDependsOnThis(tok)) {
2945-
result = findThisChanged(start, end, false, settings, cpp);
2946-
return true;
2945+
result = findThisChanged(start, end, /*indirect*/ 0, settings, cpp);
2946+
if (result)
2947+
return true;
29472948
}
29482949
bool global = false;
29492950
if (tok->variable()) {

test/testcondition.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class TestCondition : public TestFixture {
7070
TEST_CASE(incorrectLogicOperator14);
7171
TEST_CASE(incorrectLogicOperator15);
7272
TEST_CASE(incorrectLogicOperator16); // #10070
73+
TEST_CASE(incorrectLogicOperator17);
7374
TEST_CASE(secondAlwaysTrueFalseWhenFirstTrueError);
7475
TEST_CASE(incorrectLogicOp_condSwapping);
7576
TEST_CASE(testBug5895);
@@ -1722,6 +1723,24 @@ class TestCondition : public TestFixture {
17221723
ASSERT_EQUALS("", errout.str());
17231724
}
17241725

1726+
void incorrectLogicOperator17() { // #12471
1727+
check("struct R {\n"
1728+
" void set() { i = 1; }\n"
1729+
" int get() const { return i; }\n"
1730+
" int i;\n"
1731+
"};\n"
1732+
"struct P {\n"
1733+
" void f();\n"
1734+
" R* r;\n"
1735+
"};\n"
1736+
"void P::f() {\n"
1737+
" int a = r->get();\n"
1738+
" r->set();\n"
1739+
" if (a == 0 && r->get()) {}\n"
1740+
"}\n");
1741+
ASSERT_EQUALS("", errout.str());
1742+
}
1743+
17251744
void secondAlwaysTrueFalseWhenFirstTrueError() {
17261745
check("void f(void) {\n" // #8892
17271746
" const char c[1] = { \'x\' }; \n"

0 commit comments

Comments
 (0)