From 771114cd52a342059d6bfdae4db54c79f6191d6e Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Fri, 23 Aug 2024 20:49:30 +0200 Subject: [PATCH] Fix --- lib/valueflow.cpp | 5 +++-- test/testcondition.cpp | 9 +++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 72da844aa87..c19799ea412 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -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 @@ -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); } } diff --git a/test/testcondition.cpp b/test/testcondition.cpp index 45ec8d5fb24..76dc90b736f 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -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() {