Skip to content

Commit 82bdbcd

Browse files
authored
Fix issue 9859: false positive: knownConditionTrueFalse (danmar#2759)
1 parent 262d37f commit 82bdbcd

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/valueflow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2574,7 +2574,7 @@ struct SingleValueFlowForwardAnalyzer : ValueFlowForwardAnalyzer {
25742574
virtual bool isGlobal() const OVERRIDE {
25752575
for (const auto&p:getVars()) {
25762576
const Variable* var = p.second;
2577-
if (var->isGlobal() && !var->isConst())
2577+
if (!var->isLocal() && !var->isArgument() && !var->isConst())
25782578
return true;
25792579
}
25802580
return false;

test/testcondition.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3588,6 +3588,17 @@ class TestCondition : public TestFixture {
35883588
" return;\n"
35893589
"}\n");
35903590
ASSERT_EQUALS("", errout.str());
3591+
3592+
check("struct A {\n"
3593+
" std::vector<int> v;\n"
3594+
" void g();\n"
3595+
" void f(bool b) {\n"
3596+
" v.clear();\n"
3597+
" g();\n"
3598+
" return !v.empty();\n"
3599+
" }\n"
3600+
"};\n");
3601+
ASSERT_EQUALS("", errout.str());
35913602
}
35923603

35933604
void multiConditionAlwaysTrue() {

0 commit comments

Comments
 (0)