Skip to content

Commit

Permalink
Fix #12732 FP knownConditionTrueFalse with switch (regression) (#6495)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Jun 8, 2024
1 parent 35863cb commit 1638831
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/forwardanalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ namespace {
const Scope* scope = tok->scope();
if (!scope)
return Break();
if (contains({Scope::eDo, Scope::eFor, Scope::eWhile, Scope::eIf, Scope::eElse}, scope->type)) {
if (contains({Scope::eDo, Scope::eFor, Scope::eWhile, Scope::eIf, Scope::eElse, Scope::eSwitch}, scope->type)) {
const bool inElse = scope->type == Scope::eElse;
const bool inDoWhile = scope->type == Scope::eDo;
const bool inLoop = contains({Scope::eDo, Scope::eFor, Scope::eWhile}, scope->type);
Expand Down
13 changes: 13 additions & 0 deletions test/testcondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4607,6 +4607,19 @@ class TestCondition : public TestFixture {
" if (q) {}\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (style) Condition 'q' is always true\n", errout_str());

check("void f(int i) {\n"
" int j = 0;\n"
" switch (i) {\n"
" case 1:\n"
" j = 0;\n"
" break;\n"
" default:\n"
" j = 1;\n"
" }\n"
" if (j != 0) {}\n"
"}\n");
ASSERT_EQUALS("", errout_str());
}

void alwaysTrueSymbolic()
Expand Down

0 comments on commit 1638831

Please sign in to comment.