Skip to content

Commit 84782cc

Browse files
Fix #12858 FP knownConditionTrueFalse with switch in try/catch in subfunction (#6553)
1 parent 7dd7a0f commit 84782cc

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

lib/forwardanalyzer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,7 @@ namespace {
811811
} else if (Token::simpleMatch(tok, "switch (")) {
812812
if (updateRecursive(tok->next()->astOperand2()) == Progress::Break)
813813
return Break();
814+
actions |= Analyzer::Action::Write; // bailout for switch scope
814815
return Break();
815816
} else if (Token* callTok = callExpr(tok)) {
816817
// TODO: Dont traverse tokens a second time

test/testcondition.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4632,6 +4632,26 @@ class TestCondition : public TestFixture {
46324632
" return;\n"
46334633
"}\n");
46344634
ASSERT_EQUALS("", errout_str());
4635+
4636+
check("int h();\n"
4637+
"bool g() {\n"
4638+
" bool b{};\n"
4639+
" try {\n"
4640+
" int x = h();\n"
4641+
" switch (x) {\n"
4642+
" default:\n"
4643+
" b = true;\n"
4644+
" }\n"
4645+
" }\n"
4646+
" catch (...) {\n"
4647+
" b = false;\n"
4648+
" }\n"
4649+
" return b;\n"
4650+
"}\n"
4651+
"void f() {\n"
4652+
" if (g()) {}\n"
4653+
"}\n");
4654+
ASSERT_EQUALS("", errout_str());
46354655
}
46364656

46374657
void alwaysTrueSymbolic()

0 commit comments

Comments
 (0)