Support a few more common styles of "fall through" comment
This commit is contained in:
parent
5bbf39d094
commit
e12ae654a8
|
@ -310,9 +310,12 @@ static bool isFallThroughComment(std::string comment)
|
||||||
comment.erase(std::remove_if(comment.begin(), comment.end(), ::isspace), comment.end());
|
comment.erase(std::remove_if(comment.begin(), comment.end(), ::isspace), comment.end());
|
||||||
|
|
||||||
return comment.find("fallthr") != std::string::npos ||
|
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("dropthr") != std::string::npos ||
|
||||||
comment.find("passthr") != 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)
|
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;
|
++lineno;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::string comment(str, commentStart, i - commentStart);
|
std::string comment(str, commentStart, i - commentStart - 1);
|
||||||
|
|
||||||
if (isFallThroughComment(comment))
|
if (isFallThroughComment(comment))
|
||||||
{
|
{
|
||||||
|
|
|
@ -1449,6 +1449,39 @@ private:
|
||||||
// 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]: (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()
|
void selfAssignment()
|
||||||
|
|
Loading…
Reference in New Issue