Fix issue 8987: False positive knownConditionTrueFalse (#1678)
This commit is contained in:
parent
c3244cb359
commit
0ee3f678b5
|
@ -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))
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue