Fix issue 8987: False positive knownConditionTrueFalse (#1678)

This commit is contained in:
Paul Fultz II 2019-02-20 08:28:31 -06:00 committed by Daniel Marjamäki
parent c3244cb359
commit 0ee3f678b5
2 changed files with 10 additions and 1 deletions

View File

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

View File

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