Skip to content

Commit 04c885d

Browse files
authored
Fix 13478: FP knownConditionTrueFalse after member is modified (#7431)
1 parent f78e5a7 commit 04c885d

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

lib/vf_analyzers.cpp

+8-3
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ struct ValueFlowAnalyzer : Analyzer {
8585
virtual bool dependsOnThis() const {
8686
return false;
8787
}
88-
virtual bool isVariable() const {
88+
virtual bool isClassVariable() const {
8989
return false;
9090
}
9191

@@ -643,7 +643,7 @@ struct ValueFlowAnalyzer : Analyzer {
643643
if (a != Action::None)
644644
return a;
645645
}
646-
if (dependsOnThis() && exprDependsOnThis(tok, !isVariable()))
646+
if (dependsOnThis() && exprDependsOnThis(tok, !isClassVariable()))
647647
return isThisModified(tok);
648648

649649
// bailout: global non-const variables
@@ -1315,7 +1315,12 @@ struct ExpressionAnalyzer : SingleValueFlowAnalyzer {
13151315
return !local;
13161316
}
13171317

1318-
bool isVariable() const override {
1318+
bool isClassVariable() const override
1319+
{
1320+
if (expr->variable()) {
1321+
const Variable* var = expr->variable();
1322+
return !var->isLocal() && !var->isArgument() && !var->isStatic() && !var->isGlobal();
1323+
}
13191324
return expr->varId() > 0;
13201325
}
13211326

test/testcondition.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -4759,6 +4759,21 @@ class TestCondition : public TestFixture {
47594759
" return b ? 1 : 0;\n"
47604760
"}");
47614761
ASSERT_EQUALS("", errout_str());
4762+
4763+
check("struct S {\n"
4764+
" void f(int i);\n"
4765+
" bool g() const { return !m.empty(); }\n"
4766+
" std::set<int> m;\n"
4767+
"};\n"
4768+
"void S::f(int i) {\n"
4769+
" bool b = g();\n"
4770+
" auto it = m.find(i);\n"
4771+
" if (it != m.end()) {\n"
4772+
" m.erase(it);\n"
4773+
" if (g() != b) {}\n"
4774+
" }\n"
4775+
"}\n");
4776+
ASSERT_EQUALS("", errout_str());
47624777
}
47634778

47644779
void alwaysTrueSymbolic()

0 commit comments

Comments
 (0)