switchCaseFallThrough is now a coding style check (ticket #2623)
This commit is contained in:
parent
1deb4e890f
commit
8c245cfd2f
|
@ -309,6 +309,9 @@ void CheckOther::checkRedundantAssignmentInSwitch()
|
||||||
|
|
||||||
void CheckOther::checkSwitchCaseFallThrough()
|
void CheckOther::checkSwitchCaseFallThrough()
|
||||||
{
|
{
|
||||||
|
if (!_settings->_checkCodingStyle)
|
||||||
|
return;
|
||||||
|
|
||||||
const char switchPattern[] = "switch (";
|
const char switchPattern[] = "switch (";
|
||||||
const char breakPattern[] = "break|continue|return|exit|goto";
|
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)
|
void CheckOther::switchCaseFallThrough(const Token *tok)
|
||||||
{
|
{
|
||||||
reportError(tok, Severity::warning,
|
reportError(tok, Severity::style,
|
||||||
"switchCaseFallThrough", "Switch falls through case without comment");
|
"switchCaseFallThrough", "Switch falls through case without comment");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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");
|
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);
|
std::string comment(str, commentStart, i - commentStart - 1);
|
||||||
|
|
||||||
if (isFallThroughComment(comment))
|
if (_settings->_checkCodingStyle && isFallThroughComment(comment))
|
||||||
{
|
{
|
||||||
suppressionIDs.push_back("switchCaseFallThrough");
|
suppressionIDs.push_back("switchCaseFallThrough");
|
||||||
}
|
}
|
||||||
|
|
|
@ -1239,7 +1239,7 @@ private:
|
||||||
" break;\n"
|
" break;\n"
|
||||||
" }\n"
|
" }\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(
|
check_preprocess_suppress(
|
||||||
"void foo() {\n"
|
"void foo() {\n"
|
||||||
|
@ -1250,7 +1250,7 @@ private:
|
||||||
" break;\n"
|
" break;\n"
|
||||||
" }\n"
|
" }\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(
|
check_preprocess_suppress(
|
||||||
"void foo() {\n"
|
"void foo() {\n"
|
||||||
|
@ -1313,7 +1313,7 @@ private:
|
||||||
" break;\n"
|
" break;\n"
|
||||||
" }\n"
|
" }\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(
|
check_preprocess_suppress(
|
||||||
"void foo() {\n"
|
"void foo() {\n"
|
||||||
|
@ -1342,7 +1342,7 @@ private:
|
||||||
" break;\n"
|
" break;\n"
|
||||||
" }\n"
|
" }\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(
|
check_preprocess_suppress(
|
||||||
"void foo() {\n"
|
"void foo() {\n"
|
||||||
|
@ -1355,7 +1355,7 @@ private:
|
||||||
" break;\n"
|
" break;\n"
|
||||||
" }\n"
|
" }\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(
|
check_preprocess_suppress(
|
||||||
"void foo() {\n"
|
"void foo() {\n"
|
||||||
|
@ -1369,7 +1369,7 @@ private:
|
||||||
" break;\n"
|
" break;\n"
|
||||||
" }\n"
|
" }\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(
|
check_preprocess_suppress(
|
||||||
"void foo() {\n"
|
"void foo() {\n"
|
||||||
|
@ -1383,7 +1383,7 @@ private:
|
||||||
" break;\n"
|
" break;\n"
|
||||||
" }\n"
|
" }\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(
|
check_preprocess_suppress(
|
||||||
"void foo() {\n"
|
"void foo() {\n"
|
||||||
|
@ -1414,7 +1414,7 @@ private:
|
||||||
// that all paths after g() actually return. It's a pretty unusual case
|
// that all paths after g() actually return. It's a pretty unusual case
|
||||||
// (no pun intended).
|
// (no pun intended).
|
||||||
TODO_ASSERT_EQUALS("",
|
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(
|
check_preprocess_suppress(
|
||||||
"void foo() {\n"
|
"void foo() {\n"
|
||||||
|
@ -1448,7 +1448,7 @@ private:
|
||||||
// into where the goto is, but because it contains a "return", it omits
|
// into where the goto is, but because it contains a "return", it omits
|
||||||
// copying a final return after the block.
|
// copying a final return after the block.
|
||||||
TODO_ASSERT_EQUALS("",
|
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(
|
check_preprocess_suppress(
|
||||||
"void foo() {\n"
|
"void foo() {\n"
|
||||||
|
|
Loading…
Reference in New Issue