Relax detection of 'fall through' comment so it only adds a suppression if it immediately precedes 'case' or 'default'
This commit is contained in:
parent
8c245cfd2f
commit
c8394909c0
|
@ -331,6 +331,7 @@ std::string Preprocessor::removeComments(const std::string &str, const std::stri
|
||||||
unsigned char previous = 0;
|
unsigned char previous = 0;
|
||||||
bool inPreprocessorLine = false;
|
bool inPreprocessorLine = false;
|
||||||
std::vector<std::string> suppressionIDs;
|
std::vector<std::string> suppressionIDs;
|
||||||
|
bool fallThroughComment = false;
|
||||||
|
|
||||||
for (std::string::size_type i = hasbom(str) ? 3U : 0U; i < str.length(); ++i)
|
for (std::string::size_type i = hasbom(str) ? 3U : 0U; i < str.length(); ++i)
|
||||||
{
|
{
|
||||||
|
@ -412,7 +413,7 @@ std::string Preprocessor::removeComments(const std::string &str, const std::stri
|
||||||
|
|
||||||
if (_settings->_checkCodingStyle && isFallThroughComment(comment))
|
if (_settings->_checkCodingStyle && isFallThroughComment(comment))
|
||||||
{
|
{
|
||||||
suppressionIDs.push_back("switchCaseFallThrough");
|
fallThroughComment = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
code << "\n";
|
code << "\n";
|
||||||
|
@ -439,7 +440,7 @@ std::string Preprocessor::removeComments(const std::string &str, const std::stri
|
||||||
|
|
||||||
if (_settings->_checkCodingStyle && isFallThroughComment(comment))
|
if (_settings->_checkCodingStyle && isFallThroughComment(comment))
|
||||||
{
|
{
|
||||||
suppressionIDs.push_back("switchCaseFallThrough");
|
fallThroughComment = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (settings && settings->_inlineSuppressions)
|
if (settings && settings->_inlineSuppressions)
|
||||||
|
@ -467,6 +468,18 @@ std::string Preprocessor::removeComments(const std::string &str, const std::stri
|
||||||
{
|
{
|
||||||
// Not whitespace, not a comment, and not preprocessor.
|
// Not whitespace, not a comment, and not preprocessor.
|
||||||
// Must be code here!
|
// Must be code here!
|
||||||
|
|
||||||
|
// First check for a "fall through" comment match, but only
|
||||||
|
// add a suppression if the next token is 'case' or 'default'
|
||||||
|
if (fallThroughComment)
|
||||||
|
{
|
||||||
|
std::string::size_type j = str.find_first_not_of("abcdefghijklmnopqrstuvwxyz", i);
|
||||||
|
std::string tok = str.substr(i, j - i);
|
||||||
|
if (tok == "case" || tok == "default")
|
||||||
|
suppressionIDs.push_back("switchCaseFallThrough");
|
||||||
|
fallThroughComment = false;
|
||||||
|
}
|
||||||
|
|
||||||
// Add any pending inline suppressions that have accumulated.
|
// Add any pending inline suppressions that have accumulated.
|
||||||
if (!suppressionIDs.empty())
|
if (!suppressionIDs.empty())
|
||||||
{
|
{
|
||||||
|
|
|
@ -1482,6 +1482,12 @@ private:
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check_preprocess_suppress(
|
||||||
|
"void foo() {\n"
|
||||||
|
" // unrelated comment saying 'fall through'\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void selfAssignment()
|
void selfAssignment()
|
||||||
|
|
Loading…
Reference in New Issue