Skip to content

Commit 555546e

Browse files
Fix #12937 FP knownConditionTrueFalse for flags linked by condition (#6718)
@pfultz2 Is there a better way to handle this?
1 parent 2d19235 commit 555546e

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

lib/valueflow.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3821,7 +3821,8 @@ static void valueFlowConditionExpressions(const TokenList &tokenlist, const Symb
38213821
continue;
38223822
if (!isConstExpression(condTok, settings.library))
38233823
continue;
3824-
const bool is1 = (condTok->isComparisonOp() || condTok->tokType() == Token::eLogicalOp || astIsBool(condTok));
3824+
const bool isOp = condTok->isComparisonOp() || condTok->tokType() == Token::eLogicalOp;
3825+
const bool is1 = isOp || astIsBool(condTok);
38253826

38263827
Token* startTok = blockTok;
38273828
// Inner condition
@@ -3848,7 +3849,7 @@ static void valueFlowConditionExpressions(const TokenList &tokenlist, const Symb
38483849
valueFlowGenericForward(startTok, startTok->link(), a1, tokenlist, errorLogger, settings);
38493850

38503851
if (is1) {
3851-
OppositeExpressionAnalyzer a2(true, condTok2, makeConditionValue(1, condTok2, false, false, settings), settings);
3852+
OppositeExpressionAnalyzer a2(true, condTok2, makeConditionValue(isOp, condTok2, false, false, settings), settings);
38523853
valueFlowGenericForward(startTok, startTok->link(), a2, tokenlist, errorLogger, settings);
38533854
}
38543855
}

test/testcondition.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4893,6 +4893,15 @@ class TestCondition : public TestFixture {
48934893
" }\n"
48944894
"}\n");
48954895
ASSERT_EQUALS("", errout_str());
4896+
4897+
check("void f(bool a, bool b) {\n" // #12937
4898+
" bool c = !a && b;\n"
4899+
" if (a) {}\n"
4900+
" else {\n"
4901+
" if (c) {}\n"
4902+
" }\n"
4903+
"}\n");
4904+
ASSERT_EQUALS("", errout_str());
48964905
}
48974906

48984907
void alwaysTrueInfer() {

0 commit comments

Comments
 (0)