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:
parent
9c7b4c9540
commit
7b9c99003b
|
@ -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() + "'";
|
||||||
|
|
|
@ -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() {
|
||||||
|
|
Loading…
Reference in New Issue