File tree 2 files changed +23
-3
lines changed
2 files changed +23
-3
lines changed Original file line number Diff line number Diff line change @@ -85,7 +85,7 @@ struct ValueFlowAnalyzer : Analyzer {
85
85
virtual bool dependsOnThis () const {
86
86
return false ;
87
87
}
88
- virtual bool isVariable () const {
88
+ virtual bool isClassVariable () const {
89
89
return false ;
90
90
}
91
91
@@ -643,7 +643,7 @@ struct ValueFlowAnalyzer : Analyzer {
643
643
if (a != Action::None)
644
644
return a;
645
645
}
646
- if (dependsOnThis () && exprDependsOnThis (tok, !isVariable ()))
646
+ if (dependsOnThis () && exprDependsOnThis (tok, !isClassVariable ()))
647
647
return isThisModified (tok);
648
648
649
649
// bailout: global non-const variables
@@ -1315,7 +1315,12 @@ struct ExpressionAnalyzer : SingleValueFlowAnalyzer {
1315
1315
return !local;
1316
1316
}
1317
1317
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
+ }
1319
1324
return expr->varId () > 0 ;
1320
1325
}
1321
1326
Original file line number Diff line number Diff line change @@ -4759,6 +4759,21 @@ class TestCondition : public TestFixture {
4759
4759
" return b ? 1 : 0;\n "
4760
4760
" }" );
4761
4761
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 ());
4762
4777
}
4763
4778
4764
4779
void alwaysTrueSymbolic ()
You can’t perform that action at this time.
0 commit comments