missingReturn; fixed false positive with trailing return type

This commit is contained in:
Daniel Marjamäki 2021-07-08 13:50:26 +02:00
parent ef0af26d9f
commit 7cb66d56f3
4 changed files with 23 additions and 1 deletions

View File

@ -259,7 +259,9 @@ void CheckFunctions::checkMissingReturn()
continue;
if (function->type != Function::Type::eFunction && function->type != Function::Type::eOperatorEqual)
continue;
if (Token::Match(function->retDef, "void| %name% ("))
if (Token::Match(function->retDef, "%name% (") && function->retDef->isUpperCaseName())
continue;
if (Function::returnsVoid(function, true))
continue;
const Token *errorToken = checkMissingReturnScope(scope->bodyEnd);
if (errorToken)

View File

@ -2677,6 +2677,21 @@ bool Function::returnsReference(const Function* function, bool unknown)
return false;
}
bool Function::returnsVoid(const Function* function, bool unknown)
{
if (!function)
return false;
if (function->type != Function::eFunction)
return false;
const Token* defEnd = function->returnDefEnd();
if (defEnd->strAt(-1) == "void")
return true;
// Check for unknown types, which could be a void type
if (isUnknownType(function->retDef, defEnd))
return unknown;
return false;
}
std::vector<const Token*> Function::findReturns(const Function* f)
{
std::vector<const Token*> result;

View File

@ -908,6 +908,8 @@ public:
static bool returnsReference(const Function* function, bool unknown = false);
static bool returnsVoid(const Function* function, bool unknown = false);
static std::vector<const Token*> findReturns(const Function* f);
const Token* returnDefEnd() const {

View File

@ -1376,6 +1376,9 @@ private:
check("F(A,B) { x=1; }");
ASSERT_EQUALS("", errout.str());
check("auto foo4() -> void {}");
ASSERT_EQUALS("", errout.str());
// switch
check("int f() {\n"
" switch (x) {\n"