From 0ee3f678b52d0203d4b84abf65e5cac92f26a553 Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Wed, 20 Feb 2019 08:28:31 -0600 Subject: [PATCH] Fix issue 8987: False positive knownConditionTrueFalse (#1678) --- lib/checkcondition.cpp | 2 +- test/testcondition.cpp | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/checkcondition.cpp b/lib/checkcondition.cpp index 186bbb264..cfeef48c4 100644 --- a/lib/checkcondition.cpp +++ b/lib/checkcondition.cpp @@ -1331,7 +1331,7 @@ void CheckCondition::alwaysTrueFalse() if (!(constIfWhileExpression || constValExpr || compExpr || returnStatement)) continue; - if (returnStatement && scope->function && !Token::simpleMatch(scope->function->retDef, "bool")) + if (returnStatement && (!scope->function || !Token::simpleMatch(scope->function->retDef, "bool"))) continue; if (returnStatement && isConstVarExpression(tok)) diff --git a/test/testcondition.cpp b/test/testcondition.cpp index 7e525983c..2467c44ba 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -2872,6 +2872,15 @@ private: " else return 42;\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + check("long X::g(bool unknown, int& result) {\n" + " long ret = 0;\n" + " bool f = false;\n" + " f = f || unknown;\n" + " f ? result = 42 : ret = -1;\n" + " return ret;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void multiConditionAlwaysTrue() {