recognise fall through in c style comments

This commit is contained in:
Greg Hewgill 2011-02-20 09:54:01 +13:00
parent ad45737805
commit 610d2efaea
2 changed files with 21 additions and 2 deletions

View File

@ -392,7 +392,8 @@ std::string Preprocessor::removeComments(const std::string &str, const std::stri
} }
} }
if (comment.find("fall through") != std::string::npos) std::transform(comment.begin(), comment.end(), comment.begin(), ::tolower);
if (comment.find("fall") != std::string::npos && comment.find("thr") != std::string::npos)
{ {
suppressionIDs.push_back("switchCaseFallThrough"); suppressionIDs.push_back("switchCaseFallThrough");
} }
@ -417,10 +418,16 @@ std::string Preprocessor::removeComments(const std::string &str, const std::stri
++lineno; ++lineno;
} }
} }
std::string comment(str, commentStart, i - commentStart);
std::transform(comment.begin(), comment.end(), comment.begin(), ::tolower);
if (comment.find("fall") != std::string::npos && comment.find("thr") != std::string::npos)
{
suppressionIDs.push_back("switchCaseFallThrough");
}
if (settings && settings->_inlineSuppressions) if (settings && settings->_inlineSuppressions)
{ {
std::string comment(str, commentStart, i - commentStart);
std::istringstream iss(comment); std::istringstream iss(comment);
std::string word; std::string word;
iss >> word; iss >> word;

View File

@ -1263,6 +1263,18 @@ private:
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
check_preprocess_suppress(
"void foo() {\n"
" switch (a) {\n"
" case 1:\n"
" g();\n"
" /* FALLTHRU */\n"
" case 2:\n"
" break;\n"
" }\n"
"}\n");
ASSERT_EQUALS("", errout.str());
check_preprocess_suppress( check_preprocess_suppress(
"void foo() {\n" "void foo() {\n"
" switch (a) {\n" " switch (a) {\n"