Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #12471 FP incorrectLogicOperator, followVariables does not seem to care about setter #6051

Merged
merged 1 commit into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading