diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 8324808c5..97ab6ad20 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -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"); } diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index 0b2e0478f..f98578a8c 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -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"); } diff --git a/test/testother.cpp b/test/testother.cpp index 8bd040908..e5dd1481b 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -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"