From 1783fd1bba24516b564be9e2d137bedc5977550a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 29 Jun 2021 11:16:54 +0200 Subject: [PATCH] duplicateBreak; Allow extra return that clarifies for tool(s) that function does not continue --- lib/checkother.cpp | 4 ++++ test/testother.cpp | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index e0e8c07d1..14b64fe70 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -802,6 +802,10 @@ void CheckOther::checkUnreachableCode() } else if (Token::Match(tok, "%name% (") && mSettings->library.isnoreturn(tok) && !Token::Match(tok->next()->astParent(), "?|:")) { if ((!tok->function() || (tok->function()->token != tok && tok->function()->tokenDef != tok)) && tok->linkAt(1)->strAt(1) != "{") secondBreak = tok->linkAt(1)->tokAt(2); + if (Token::simpleMatch(secondBreak, "return")) { + // clarification for tools that function returns + continue; + } } // Statements follow directly, no line between them. (#3383) diff --git a/test/testother.cpp b/test/testother.cpp index 38eb28cd0..274890f02 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -3772,6 +3772,12 @@ private: " bar();\n" "}", nullptr, false, false, false, false, &settings), InternalError); //ASSERT_EQUALS("", errout.str()); + + check("int foo() {\n" + " exit(0);\n" + " return 1;\n" // <- clarify for tools that function does not continue.. + "}"); + ASSERT_EQUALS("", errout.str()); }