From f3bea249ac3449fba1415bc4ebcbf5e1aa75c461 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 24 Apr 2010 14:30:45 +0200 Subject: [PATCH] Removed the check for unreachable code. The g++ warning -Wunreachable-code is recommended instead. This closes #1603 (break after a return or goto should not be an error in a switch statement). --- lib/checkother.cpp | 49 ---------------------------------------------- lib/checkother.h | 5 ----- test/testother.cpp | 18 ----------------- 3 files changed, 72 deletions(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index d6cfc801a..aae43d771 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -402,55 +402,6 @@ void CheckOther::checkUnsignedDivision() - - -//--------------------------------------------------------------------------- -// Unreachable code below a 'return' -//--------------------------------------------------------------------------- - -void CheckOther::unreachableCode() -{ - if (!_settings->_checkCodingStyle) - return; - - const Token *tok = _tokenizer->tokens(); - while ((tok = Token::findmatch(tok, "[;{}] return")) != NULL) - { - // Goto the 'return' token - tok = tok->next(); - - // Locate the end of the 'return' statement - while (tok && tok->str() != ";") - tok = tok->next(); - while (tok && tok->next() && tok->next()->str() == ";") - tok = tok->next(); - - if (!tok) - break; - - // If there is a statement below the return it is unreachable - /* original: - if (!Token::Match(tok, "; case|default|}|#") && - !Token::Match(tok, "; %var% :") && - !Token::simpleMatch(tok, "; break")) - */ - if (Token::simpleMatch(tok, "; break")) - { - unreachableCodeError(tok->next()); - } - } -} - -void CheckOther::unreachableCodeError(const Token *tok) -{ - reportError(tok, Severity::style, "unreachableCode", "Unreachable code below a 'return'"); -} - -//--------------------------------------------------------------------------- - - - - //--------------------------------------------------------------------------- // Usage of function variables //--------------------------------------------------------------------------- diff --git a/lib/checkother.h b/lib/checkother.h index 89295ffde..e30c70bd5 100644 --- a/lib/checkother.h +++ b/lib/checkother.h @@ -70,7 +70,6 @@ public: checkOther.warningRedundantCode(); checkOther.checkConstantFunctionParameter(); checkOther.checkIncompleteStatement(); - checkOther.unreachableCode(); checkOther.checkEmptyStringTest(); checkOther.postIncrement(); @@ -110,10 +109,6 @@ public: /** @brief %Check for unsigned division */ void checkUnsignedDivision(); - /** @brief %Check for unreachable code */ - void unreachableCode(); - void unreachableCodeError(const Token *tok); - /** @brief %Check for unused function variables */ void functionVariableUsage(); void unusedVariableError(const Token *tok, const std::string &varname); diff --git a/test/testother.cpp b/test/testother.cpp index 9a202a347..c2f450dde 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -42,8 +42,6 @@ private: TEST_CASE(delete1); TEST_CASE(delete2); - TEST_CASE(unreachable1); - TEST_CASE(sprintf1); // Dangerous usage of sprintf TEST_CASE(sprintf2); TEST_CASE(sprintf3); @@ -115,7 +113,6 @@ private: CheckOther checkOther(&tokenizer, &settings, this); checkOther.warningRedundantCode(); checkOther.checkZeroDivision(); - checkOther.unreachableCode(); checkOther.checkMathFunctions(); checkOther.checkEmptyStringTest(); } @@ -361,21 +358,6 @@ private: ASSERT_EQUALS("[test.cpp:3]: (style) Redundant condition. It is safe to deallocate a NULL pointer\n", errout.str()); } - void unreachable1() - { - check("void foo()\n" - "{\n" - " switch (p)\n" - " {\n" - " default:\n" - " return 0;\n" - " break;\n" - " }\n" - "}\n"); - ASSERT_EQUALS("[test.cpp:7]: (style) Unreachable code below a 'return'\n", errout.str()); - } - - void sprintfUsage(const char code[]) {