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()