From 53955b48d2d955894bb786beb803166510aba312 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 10 Jul 2021 08:49:48 +0200 Subject: [PATCH] missingReturn; Fixed false negative for goto-label --- lib/checkfunctions.cpp | 2 ++ test/testfunctions.cpp | 7 +++++++ 2 files changed, 9 insertions(+) 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"