Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Aug 23, 2024
1 parent 6faed30 commit 771114c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/valueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3821,7 +3821,8 @@ static void valueFlowConditionExpressions(const TokenList &tokenlist, const Symb
continue;
if (!isConstExpression(condTok, settings.library))
continue;
const bool is1 = (condTok->isComparisonOp() || condTok->tokType() == Token::eLogicalOp || astIsBool(condTok));
const bool isOp = condTok->isComparisonOp() || condTok->tokType() == Token::eLogicalOp;
const bool is1 = isOp || astIsBool(condTok);

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

if (is1) {
OppositeExpressionAnalyzer a2(true, condTok2, makeConditionValue(1, condTok2, false, false, settings), settings);
OppositeExpressionAnalyzer a2(true, condTok2, makeConditionValue(isOp, condTok2, false, false, settings), settings);
valueFlowGenericForward(startTok, startTok->link(), a2, tokenlist, errorLogger, settings);
}
}
Expand Down
9 changes: 9 additions & 0 deletions test/testcondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4893,6 +4893,15 @@ class TestCondition : public TestFixture {
" }\n"
"}\n");
ASSERT_EQUALS("", errout_str());

check("void f(bool a, bool b) {\n" // #12937
" bool c = !a && b;\n"
" if (a) {}\n"
" else {\n"
" if (c) {}\n"
" }\n"
"}\n");
ASSERT_EQUALS("", errout_str());
}

void alwaysTrueInfer() {
Expand Down

0 comments on commit 771114c

Please sign in to comment.