diff --git a/lib/checkfunctions.cpp b/lib/checkfunctions.cpp index 25fbce3f3..d5ef96fb6 100644 --- a/lib/checkfunctions.cpp +++ b/lib/checkfunctions.cpp @@ -314,6 +314,8 @@ static const Token *checkMissingReturnScope(const Token *tok) } if (tok->isKeyword() && Token::Match(tok, "return|throw")) return nullptr; + if (Token::Match(tok, "[;{}] %name% :")) + return tok; if (Token::Match(tok, "; !!}") && !lastStatement) lastStatement = tok->next(); } diff --git a/test/testfunctions.cpp b/test/testfunctions.cpp index 46ab8a447..77cd83a41 100644 --- a/test/testfunctions.cpp +++ b/test/testfunctions.cpp @@ -1386,6 +1386,13 @@ private: "}"); ASSERT_EQUALS("", errout.str()); + check("int foo(int x) {\n" + " if (x) goto out;\n" + " return 1;\n" + "out:\n" + "}"); + 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()); + // switch check("int f() {\n" " switch (x) {\n"