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
This commit is contained in:
chrchr-github 2022-10-20 07:00:36 +02:00 committed by GitHub
parent 9c7b4c9540
commit 7b9c99003b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -852,7 +852,7 @@ void CheckOther::duplicateBreakError(const Token *tok, bool inconclusive)
void CheckOther::unreachableCodeError(const Token *tok, const Token* noreturn, bool inconclusive) void CheckOther::unreachableCodeError(const Token *tok, const Token* noreturn, bool inconclusive)
{ {
std::string msg = "Statements following "; std::string msg = "Statements following ";
if (noreturn && noreturn->function()) if (noreturn && (noreturn->function() || mSettings->library.isnoreturn(noreturn)))
msg += "noreturn function '" + noreturn->str() + "()'"; msg += "noreturn function '" + noreturn->str() + "()'";
else if (noreturn && noreturn->isKeyword()) else if (noreturn && noreturn->isKeyword())
msg += "'" + noreturn->str() + "'"; msg += "'" + noreturn->str() + "'";

View File

@ -4503,6 +4503,20 @@ private:
" g();\n" " g();\n"
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:4]: (style) Statements following noreturn function 'n()' will never be executed.\n", errout.str()); 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() { void redundantContinue() {