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:
parent
1eafe45c47
commit
f3bea249ac
|
@ -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
|
// Usage of function variables
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
|
@ -70,7 +70,6 @@ public:
|
||||||
checkOther.warningRedundantCode();
|
checkOther.warningRedundantCode();
|
||||||
checkOther.checkConstantFunctionParameter();
|
checkOther.checkConstantFunctionParameter();
|
||||||
checkOther.checkIncompleteStatement();
|
checkOther.checkIncompleteStatement();
|
||||||
checkOther.unreachableCode();
|
|
||||||
checkOther.checkEmptyStringTest();
|
checkOther.checkEmptyStringTest();
|
||||||
checkOther.postIncrement();
|
checkOther.postIncrement();
|
||||||
|
|
||||||
|
@ -110,10 +109,6 @@ public:
|
||||||
/** @brief %Check for unsigned division */
|
/** @brief %Check for unsigned division */
|
||||||
void checkUnsignedDivision();
|
void checkUnsignedDivision();
|
||||||
|
|
||||||
/** @brief %Check for unreachable code */
|
|
||||||
void unreachableCode();
|
|
||||||
void unreachableCodeError(const Token *tok);
|
|
||||||
|
|
||||||
/** @brief %Check for unused function variables */
|
/** @brief %Check for unused function variables */
|
||||||
void functionVariableUsage();
|
void functionVariableUsage();
|
||||||
void unusedVariableError(const Token *tok, const std::string &varname);
|
void unusedVariableError(const Token *tok, const std::string &varname);
|
||||||
|
|
|
@ -42,8 +42,6 @@ private:
|
||||||
TEST_CASE(delete1);
|
TEST_CASE(delete1);
|
||||||
TEST_CASE(delete2);
|
TEST_CASE(delete2);
|
||||||
|
|
||||||
TEST_CASE(unreachable1);
|
|
||||||
|
|
||||||
TEST_CASE(sprintf1); // Dangerous usage of sprintf
|
TEST_CASE(sprintf1); // Dangerous usage of sprintf
|
||||||
TEST_CASE(sprintf2);
|
TEST_CASE(sprintf2);
|
||||||
TEST_CASE(sprintf3);
|
TEST_CASE(sprintf3);
|
||||||
|
@ -115,7 +113,6 @@ private:
|
||||||
CheckOther checkOther(&tokenizer, &settings, this);
|
CheckOther checkOther(&tokenizer, &settings, this);
|
||||||
checkOther.warningRedundantCode();
|
checkOther.warningRedundantCode();
|
||||||
checkOther.checkZeroDivision();
|
checkOther.checkZeroDivision();
|
||||||
checkOther.unreachableCode();
|
|
||||||
checkOther.checkMathFunctions();
|
checkOther.checkMathFunctions();
|
||||||
checkOther.checkEmptyStringTest();
|
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());
|
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[])
|
void sprintfUsage(const char code[])
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue