missingReturn; Fixed false positive when if condition is always true
This commit is contained in:
parent
a336c07663
commit
e4ecfd7be8
|
@ -316,6 +316,9 @@ static const Token *checkMissingReturnScope(const Token *tok, const Library &lib
|
||||||
if (!hasDefault)
|
if (!hasDefault)
|
||||||
return tok->link();
|
return tok->link();
|
||||||
} else if (tok->scope()->type == Scope::ScopeType::eIf) {
|
} else if (tok->scope()->type == Scope::ScopeType::eIf) {
|
||||||
|
const Token *condition = tok->scope()->classDef->next()->astOperand2();
|
||||||
|
if (condition && condition->hasKnownIntValue() && condition->getKnownIntValue() == 1)
|
||||||
|
return checkMissingReturnScope(tok, library);
|
||||||
return tok;
|
return tok;
|
||||||
} else if (tok->scope()->type == Scope::ScopeType::eElse) {
|
} else if (tok->scope()->type == Scope::ScopeType::eElse) {
|
||||||
const Token *errorToken = checkMissingReturnScope(tok, library);
|
const Token *errorToken = checkMissingReturnScope(tok, library);
|
||||||
|
|
|
@ -1436,6 +1436,18 @@ private:
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (error) Found a exit path from function with non-void return type that has missing return statement\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (error) Found a exit path from function with non-void return type that has missing return statement\n", errout.str());
|
||||||
|
|
||||||
|
check("int f() {\n"
|
||||||
|
" if (!0) {\n"
|
||||||
|
" return 1;\n"
|
||||||
|
" }\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check("int f() {\n"
|
||||||
|
" if (!0) {}\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("[test.cpp:2]: (error) Found a exit path from function with non-void return type that has missing return statement\n", errout.str());
|
||||||
|
|
||||||
// loop
|
// loop
|
||||||
check("int f(int x) {\n"
|
check("int f(int x) {\n"
|
||||||
" while (1) {\n"
|
" while (1) {\n"
|
||||||
|
|
Loading…
Reference in New Issue