diff --git a/lib/checkfunctions.cpp b/lib/checkfunctions.cpp index c306f422dcf..639b54a252b 100644 --- a/lib/checkfunctions.cpp +++ b/lib/checkfunctions.cpp @@ -399,7 +399,10 @@ static const Token *checkMissingReturnScope(const Token *tok, const Library &lib return nullptr; if (tok->str() == "goto" && !isForwardJump(tok)) return nullptr; - if (Token::Match(tok, "%name% (") && !library.isnotnoreturn(tok)) { + if (Token::Match(tok, "%name% (") && library.isnoreturn(tok)) { + return nullptr; + } + if (Token::Match(tok->previous(), "[;{}] %name% (") && !library.isnotnoreturn(tok)) { return nullptr; } if (Token::Match(tok, "[;{}] %name% :")) diff --git a/test/testfunctions.cpp b/test/testfunctions.cpp index da756b02ace..a2f2ad5a069 100644 --- a/test/testfunctions.cpp +++ b/test/testfunctions.cpp @@ -79,6 +79,7 @@ class TestFunctions : public TestFixture { TEST_CASE(checkMissingReturn3); TEST_CASE(checkMissingReturn4); TEST_CASE(checkMissingReturn5); + TEST_CASE(checkMissingReturn6); // #13180 // std::move for locar variable TEST_CASE(returnLocalStdMove1); @@ -1777,7 +1778,7 @@ class TestFunctions : public TestFixture { " return 2;\n" " }\n" "}\n" - "int _tmain(int argc, _TCHAR* argv[])\n" + "int main(int argc, char* argv[])\n" "{\n" " auto const b= f(true);\n" " auto const c= f(false);\n" @@ -1845,6 +1846,14 @@ class TestFunctions : public TestFixture { ASSERT_EQUALS("", errout_str()); } + void checkMissingReturn6() {// #13180 + check("int foo(void)\n" + "{\n" + " i = readData();\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:3]: (error) Found an exit path from function with non-void return type that has missing return statement\n", errout_str()); + } + // NRVO check void returnLocalStdMove1() { check("struct A{}; A f() { A var; return std::move(var); }");