From bdbd84ba9824c83af25cea16ee6c3d4bc6262132 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 9 Aug 2022 13:13:16 +0200 Subject: [PATCH] #11238: Fix regression (#4349) * Fix #11238 FP knownConditionTrueFalse with constexpr? * Modify isConstVarExpression() * Use predicate * Format * #11238: Fix regression --- lib/astutils.cpp | 2 +- test/testcondition.cpp | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/astutils.cpp b/lib/astutils.cpp index e947dc4bc..65c9d89d7 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -2784,7 +2784,7 @@ bool isConstVarExpression(const Token *tok, std::function sk std::vector args = getArguments(tok); if (args.empty() && tok->previous()->function() && tok->previous()->function()->isConstexpr()) return true; - return std::all_of(args.begin(), args.end(), [&](const Token* t) { + return !args.empty() && std::all_of(args.begin(), args.end(), [&](const Token* t) { return isConstVarExpression(t, skipPredicate); }); } diff --git a/test/testcondition.cpp b/test/testcondition.cpp index 42a57e186..66aa5a080 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -4289,6 +4289,14 @@ private: " return f() == 1;\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + check("int g() { return -1; }\n" + "void f() {\n" + " if (g() == 1 && g() == -1) {}\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:3]: (style) Condition 'g()==1' is always false\n" + "[test.cpp:3]: (style) Condition 'g()==-1' is always true\n", + errout.str()); } void alwaysTrueSymbolic()