Skip to content

Commit df2a720

Browse files
committed
Fix #12732 FP knownConditionTrueFalse with switch (regression)
1 parent dc385f3 commit df2a720

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

Diff for: lib/forwardanalyzer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ namespace {
614614
const Scope* scope = tok->scope();
615615
if (!scope)
616616
return Break();
617-
if (contains({Scope::eDo, Scope::eFor, Scope::eWhile, Scope::eIf, Scope::eElse}, scope->type)) {
617+
if (contains({Scope::eDo, Scope::eFor, Scope::eWhile, Scope::eIf, Scope::eElse, Scope::eSwitch}, scope->type)) {
618618
const bool inElse = scope->type == Scope::eElse;
619619
const bool inDoWhile = scope->type == Scope::eDo;
620620
const bool inLoop = contains({Scope::eDo, Scope::eFor, Scope::eWhile}, scope->type);

Diff for: test/testcondition.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -4607,6 +4607,19 @@ class TestCondition : public TestFixture {
46074607
" if (q) {}\n"
46084608
"}\n");
46094609
ASSERT_EQUALS("[test.cpp:4]: (style) Condition 'q' is always true\n", errout_str());
4610+
4611+
check("void f(int i) {\n"
4612+
" int j = 0;\n"
4613+
" switch (i) {\n"
4614+
" case 1:\n"
4615+
" j = 0;\n"
4616+
" break;\n"
4617+
" default:\n"
4618+
" j = 1;\n"
4619+
" }\n"
4620+
" if (j != 0) {}\n"
4621+
"}\n");
4622+
ASSERT_EQUALS("", errout_str());
46104623
}
46114624

46124625
void alwaysTrueSymbolic()

0 commit comments

Comments
 (0)