diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 6d10abcc0..5dd6075d1 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -852,7 +852,7 @@ void CheckOther::duplicateBreakError(const Token *tok, bool inconclusive) void CheckOther::unreachableCodeError(const Token *tok, const Token* noreturn, bool inconclusive) { std::string msg = "Statements following "; - if (noreturn && noreturn->function()) + if (noreturn && (noreturn->function() || mSettings->library.isnoreturn(noreturn))) msg += "noreturn function '" + noreturn->str() + "()'"; else if (noreturn && noreturn->isKeyword()) msg += "'" + noreturn->str() + "'"; diff --git a/test/testother.cpp b/test/testother.cpp index 83fb7557b..b0008c667 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -4503,6 +4503,20 @@ private: " g();\n" "}\n"); ASSERT_EQUALS("[test.cpp:4]: (style) Statements following noreturn function 'n()' will never be executed.\n", errout.str()); + + check("void f() {\n" + " exit(1);\n" + " g();\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:3]: (style) Statements following noreturn function 'exit()' will never be executed.\n", errout.str()); + + check("void f() {\n" + " do {\n" + " break;\n" + " g();\n" + " } while (0);\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:4]: (style) Statements following 'break' will never be executed.\n", errout.str()); } void redundantContinue() {