Fix issue 8841: FP knownConditionTrueFalse - Dont treat unknown function as noreturn (#1474)
* Fix issue 8841: Dont treat unknown function as noreturn * Add a parameter to set default value when the function is unknown
This commit is contained in:
parent
ee2dfb6604
commit
e46691597e
|
@ -304,13 +304,17 @@ static const Token * skipValueInConditionalExpression(const Token * const valuet
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool isEscapeScope(const Token* tok, TokenList * tokenlist)
|
static bool isEscapeScope(const Token* tok, TokenList * tokenlist, bool unknown = false)
|
||||||
{
|
{
|
||||||
if (!Token::simpleMatch(tok, "{"))
|
if (!Token::simpleMatch(tok, "{"))
|
||||||
return false;
|
return false;
|
||||||
const Token * termTok = Token::findmatch(tok, "return|continue|break|throw|goto", tok->link());
|
const Token * termTok = Token::findmatch(tok, "return|continue|break|throw|goto", tok->link());
|
||||||
return (termTok && termTok->scope() == tok->scope()) ||
|
if(termTok && termTok->scope() == tok->scope())
|
||||||
(tokenlist && tokenlist->getSettings()->library.isScopeNoReturn(tok->link(), nullptr));
|
return true;
|
||||||
|
std::string unknownFunction;
|
||||||
|
if(tokenlist && tokenlist->getSettings()->library.isScopeNoReturn(tok->link(), &unknownFunction))
|
||||||
|
return unknownFunction.empty() || unknown;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool bailoutSelfAssignment(const Token * const tok)
|
static bool bailoutSelfAssignment(const Token * const tok)
|
||||||
|
@ -4227,7 +4231,7 @@ static void valueFlowContainerSize(TokenList *tokenlist, SymbolDatabase* symbold
|
||||||
valueFlowContainerReverse(scope.classDef, tok->varId(), value, settings);
|
valueFlowContainerReverse(scope.classDef, tok->varId(), value, settings);
|
||||||
|
|
||||||
// possible value after condition
|
// possible value after condition
|
||||||
if (!isEscapeScope(scope.bodyStart, tokenlist)) {
|
if (!isEscapeScope(scope.bodyStart, tokenlist, true)) {
|
||||||
const Token *after = scope.bodyEnd;
|
const Token *after = scope.bodyEnd;
|
||||||
if (Token::simpleMatch(after, "} else {"))
|
if (Token::simpleMatch(after, "} else {"))
|
||||||
after = isEscapeScope(after->tokAt(2), tokenlist) ? nullptr : after->linkAt(2);
|
after = isEscapeScope(after->tokAt(2), tokenlist) ? nullptr : after->linkAt(2);
|
||||||
|
|
|
@ -2683,6 +2683,16 @@ private:
|
||||||
" return;\n"
|
" return;\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check("void foo(int i) {\n"
|
||||||
|
" if (i==42)\n"
|
||||||
|
" {\n"
|
||||||
|
" bar();\n"
|
||||||
|
" }\n"
|
||||||
|
" if (cond && (42==i))\n"
|
||||||
|
" return;\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void multiConditionAlwaysTrue() {
|
void multiConditionAlwaysTrue() {
|
||||||
|
|
Loading…
Reference in New Issue