diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index d93ddd6ab..0b2e0478f 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -310,9 +310,12 @@ static bool isFallThroughComment(std::string comment) comment.erase(std::remove_if(comment.begin(), comment.end(), ::isspace), comment.end()); return comment.find("fallthr") != std::string::npos || + comment.find("fallsthr") != std::string::npos || + comment.find("fall-thr") != std::string::npos || comment.find("dropthr") != std::string::npos || comment.find("passthr") != std::string::npos || - comment.find("nobreak") != std::string::npos; + comment.find("nobreak") != std::string::npos || + comment == "fall"; } std::string Preprocessor::removeComments(const std::string &str, const std::string &filename, Settings *settings) @@ -432,7 +435,7 @@ std::string Preprocessor::removeComments(const std::string &str, const std::stri ++lineno; } } - std::string comment(str, commentStart, i - commentStart); + std::string comment(str, commentStart, i - commentStart - 1); if (isFallThroughComment(comment)) { diff --git a/test/testother.cpp b/test/testother.cpp index 7aab2c4da..8bd040908 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -1449,6 +1449,39 @@ private: // copying a final return after the block. TODO_ASSERT_EQUALS("", "[test.cpp:5]: (warning) Switch falls through case without comment\n", errout.str()); + + check_preprocess_suppress( + "void foo() {\n" + " switch (a) {\n" + " case 1:\n" + " g();\n" + " // fall through\n" + " case 2:\n" + " g();\n" + " // falls through\n" + " case 3:\n" + " g();\n" + " // fall-through\n" + " case 4:\n" + " g();\n" + " // drop through\n" + " case 5:\n" + " g();\n" + " // pass through\n" + " case 5:\n" + " g();\n" + " // no break\n" + " case 5:\n" + " g();\n" + " // fallthru\n" + " case 6:\n" + " g();\n" + " /* fall */\n" + " default:\n" + " break;\n" + " }\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void selfAssignment()