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).

This commit is contained in:
Daniel Marjamäki 2010-04-24 14:30:45 +02:00
parent 1eafe45c47
commit f3bea249ac
3 changed files with 0 additions and 72 deletions

View File

@ -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
//---------------------------------------------------------------------------

View File

@ -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);

View File

@ -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[])
{