switchCaseFallThrough is now a coding style check (ticket #2623)

This commit is contained in:
Greg Hewgill 2011-03-06 09:42:15 +13:00
parent 1deb4e890f
commit 8c245cfd2f
3 changed files with 15 additions and 12 deletions

View File

@ -309,6 +309,9 @@ void CheckOther::checkRedundantAssignmentInSwitch()
void CheckOther::checkSwitchCaseFallThrough()
{
if (!_settings->_checkCodingStyle)
return;
const char switchPattern[] = "switch (";
const char breakPattern[] = "break|continue|return|exit|goto";
@ -3168,7 +3171,7 @@ void CheckOther::redundantAssignmentInSwitchError(const Token *tok, const std::s
void CheckOther::switchCaseFallThrough(const Token *tok)
{
reportError(tok, Severity::warning,
reportError(tok, Severity::style,
"switchCaseFallThrough", "Switch falls through case without comment");
}

View File

@ -410,7 +410,7 @@ std::string Preprocessor::removeComments(const std::string &str, const std::stri
}
}
if (isFallThroughComment(comment))
if (_settings->_checkCodingStyle && isFallThroughComment(comment))
{
suppressionIDs.push_back("switchCaseFallThrough");
}
@ -437,7 +437,7 @@ std::string Preprocessor::removeComments(const std::string &str, const std::stri
}
std::string comment(str, commentStart, i - commentStart - 1);
if (isFallThroughComment(comment))
if (_settings->_checkCodingStyle && isFallThroughComment(comment))
{
suppressionIDs.push_back("switchCaseFallThrough");
}

View File

@ -1239,7 +1239,7 @@ private:
" break;\n"
" }\n"
"}\n");
ASSERT_EQUALS("[test.cpp:5]: (warning) Switch falls through case without comment\n", errout.str());
ASSERT_EQUALS("[test.cpp:5]: (style) Switch falls through case without comment\n", errout.str());
check_preprocess_suppress(
"void foo() {\n"
@ -1250,7 +1250,7 @@ private:
" break;\n"
" }\n"
"}\n");
ASSERT_EQUALS("[test.cpp:5]: (warning) Switch falls through case without comment\n", errout.str());
ASSERT_EQUALS("[test.cpp:5]: (style) Switch falls through case without comment\n", errout.str());
check_preprocess_suppress(
"void foo() {\n"
@ -1313,7 +1313,7 @@ private:
" break;\n"
" }\n"
"}\n");
ASSERT_EQUALS("[test.cpp:7]: (warning) Switch falls through case without comment\n", errout.str());
ASSERT_EQUALS("[test.cpp:7]: (style) Switch falls through case without comment\n", errout.str());
check_preprocess_suppress(
"void foo() {\n"
@ -1342,7 +1342,7 @@ private:
" break;\n"
" }\n"
"}\n");
ASSERT_EQUALS("[test.cpp:8]: (warning) Switch falls through case without comment\n", errout.str());
ASSERT_EQUALS("[test.cpp:8]: (style) Switch falls through case without comment\n", errout.str());
check_preprocess_suppress(
"void foo() {\n"
@ -1355,7 +1355,7 @@ private:
" break;\n"
" }\n"
"}\n");
ASSERT_EQUALS("[test.cpp:7]: (warning) Switch falls through case without comment\n", errout.str());
ASSERT_EQUALS("[test.cpp:7]: (style) Switch falls through case without comment\n", errout.str());
check_preprocess_suppress(
"void foo() {\n"
@ -1369,7 +1369,7 @@ private:
" break;\n"
" }\n"
"}\n");
ASSERT_EQUALS("[test.cpp:8]: (warning) Switch falls through case without comment\n", errout.str());
ASSERT_EQUALS("[test.cpp:8]: (style) Switch falls through case without comment\n", errout.str());
check_preprocess_suppress(
"void foo() {\n"
@ -1383,7 +1383,7 @@ private:
" break;\n"
" }\n"
"}\n");
ASSERT_EQUALS("[test.cpp:5]: (warning) Switch falls through case without comment\n", errout.str());
ASSERT_EQUALS("[test.cpp:5]: (style) Switch falls through case without comment\n", errout.str());
check_preprocess_suppress(
"void foo() {\n"
@ -1414,7 +1414,7 @@ private:
// that all paths after g() actually return. It's a pretty unusual case
// (no pun intended).
TODO_ASSERT_EQUALS("",
"[test.cpp:11]: (warning) Switch falls through case without comment\n", errout.str());
"[test.cpp:11]: (style) Switch falls through case without comment\n", errout.str());
check_preprocess_suppress(
"void foo() {\n"
@ -1448,7 +1448,7 @@ private:
// into where the goto is, but because it contains a "return", it omits
// copying a final return after the block.
TODO_ASSERT_EQUALS("",
"[test.cpp:5]: (warning) Switch falls through case without comment\n", errout.str());
"[test.cpp:5]: (style) Switch falls through case without comment\n", errout.str());
check_preprocess_suppress(
"void foo() {\n"