From dccebb98ea78a9f0469b819ae5a313c58d33add8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 1 Sep 2021 19:49:53 +0200 Subject: [PATCH] Removed missingReturn inconclusive warnings, that was too noisy --- lib/checkfunctions.cpp | 19 +++---------------- lib/checkfunctions.h | 2 +- test/testfunctions.cpp | 3 --- 3 files changed, 4 insertions(+), 20 deletions(-) diff --git a/lib/checkfunctions.cpp b/lib/checkfunctions.cpp index d4d87141e..a509a568d 100644 --- a/lib/checkfunctions.cpp +++ b/lib/checkfunctions.cpp @@ -252,7 +252,6 @@ static const Token *checkMissingReturnScope(const Token *tok, const Library &lib void CheckFunctions::checkMissingReturn() { - const bool inconclusive = mSettings->certainty.isEnabled(Certainty::inconclusive); const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase(); for (const Scope *scope : symbolDatabase->functionScopes) { const Function *function = scope->function; @@ -267,20 +266,8 @@ void CheckFunctions::checkMissingReturn() if (Function::returnsVoid(function, true)) continue; const Token *errorToken = checkMissingReturnScope(scope->bodyEnd, mSettings->library); - if (errorToken) { + if (errorToken) missingReturnError(errorToken); - continue; - } - if (inconclusive && Token::simpleMatch(scope->bodyEnd->tokAt(-2), ") ; }")) { - const Token *ftok = scope->bodyEnd->linkAt(-2)->previous(); - if (mSettings->library.isNotLibraryFunction(ftok)) { - const Token *tok = ftok; - while (Token::Match(tok->tokAt(-2), "%name% :: %name%")) - tok = tok->tokAt(-2); - if (Token::Match(tok->previous(), "[;{}] %name% (|::") && !tok->isKeyword()) - missingReturnError(tok, Certainty::inconclusive); - } - } } } @@ -366,10 +353,10 @@ static const Token *checkMissingReturnScope(const Token *tok, const Library &lib return nullptr; } -void CheckFunctions::missingReturnError(const Token* tok, Certainty::CertaintyLevel certainty) +void CheckFunctions::missingReturnError(const Token* tok) { reportError(tok, Severity::error, "missingReturn", - "Found a exit path from function with non-void return type that has missing return statement", CWE758, certainty); + "Found a exit path from function with non-void return type that has missing return statement", CWE758, Certainty::normal); } //--------------------------------------------------------------------------- // Detect passing wrong values to functions like atan(0, x); diff --git a/lib/checkfunctions.h b/lib/checkfunctions.h index 953489d99..0fe90de73 100644 --- a/lib/checkfunctions.h +++ b/lib/checkfunctions.h @@ -120,7 +120,7 @@ private: void memsetZeroBytesError(const Token *tok); void memsetFloatError(const Token *tok, const std::string &var_value); void memsetValueOutOfRangeError(const Token *tok, const std::string &value); - void missingReturnError(const Token *tok, Certainty::CertaintyLevel certainty=Certainty::normal); + void missingReturnError(const Token *tok); void copyElisionError(const Token *tok); void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const OVERRIDE { diff --git a/test/testfunctions.cpp b/test/testfunctions.cpp index 06dca67cf..84432a054 100644 --- a/test/testfunctions.cpp +++ b/test/testfunctions.cpp @@ -1493,9 +1493,6 @@ private: check("int f(int x) { assert(0); }"); ASSERT_EQUALS("", errout.str()); - - check("int f(int x) { RETURN(0); }"); - ASSERT_EQUALS("[test.cpp:1]: (error, inconclusive) Found a exit path from function with non-void return type that has missing return statement\n", errout.str()); } // NRVO check