From 7b9c99003bd6b5d2f99eee86bc74cb562f2a4e45 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 20 Oct 2022 07:00:36 +0200 Subject: [PATCH] Improve unreachableCodeError: handle library functions (#4560) * Update templatesimplifier.cpp * Add tests * Improve unreachableCodeError message * Update templatesimplifier.cpp * Add tests * Improve unreachableCodeError message * Revert "Update templatesimplifier.cpp" This reverts commit 3fd152ed4063772a5f162bd985c3d91bcc65eb55. * Revert "Add tests" This reverts commit e760ab51e66a0a2c3a0250caf4cf3b745db44d10. * Improve unreachableCodeError: handle library functions * Fix merge --- lib/checkother.cpp | 2 +- test/testother.cpp | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) 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() {