Fixed #2740 (inline cmd // cppcheck-suppress does not work anymore for 1.48)
This commit is contained in:
parent
3fc1db51d1
commit
6fc59b0257
|
@ -468,6 +468,24 @@ std::string Preprocessor::removeComments(const std::string &str, const std::stri
|
||||||
code << ch;
|
code << ch;
|
||||||
previous = ch;
|
previous = ch;
|
||||||
inPreprocessorLine = true;
|
inPreprocessorLine = true;
|
||||||
|
|
||||||
|
// Add any pending inline suppressions that have accumulated.
|
||||||
|
if (!suppressionIDs.empty())
|
||||||
|
{
|
||||||
|
if (settings != NULL)
|
||||||
|
{
|
||||||
|
// Add the suppressions.
|
||||||
|
for (size_t j(0); j < suppressionIDs.size(); ++j)
|
||||||
|
{
|
||||||
|
const std::string errmsg(settings->nomsg.addSuppression(suppressionIDs[j], filename, lineno));
|
||||||
|
if (!errmsg.empty())
|
||||||
|
{
|
||||||
|
writeError(filename, lineno, _errorLogger, "cppcheckError", errmsg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
suppressionIDs.clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1917,7 +1935,7 @@ void Preprocessor::handleIncludes(std::string &code, const std::string &filePath
|
||||||
std::string f = filePath;
|
std::string f = filePath;
|
||||||
|
|
||||||
// Determine line number of include
|
// Determine line number of include
|
||||||
unsigned int linenr = 0;
|
unsigned int linenr = 1;
|
||||||
unsigned int level = 0;
|
unsigned int level = 0;
|
||||||
for (std::string::size_type p = 1; p <= pos; ++p)
|
for (std::string::size_type p = 1; p <= pos; ++p)
|
||||||
{
|
{
|
||||||
|
@ -1931,6 +1949,7 @@ void Preprocessor::handleIncludes(std::string &code, const std::string &filePath
|
||||||
{
|
{
|
||||||
if (level == 0)
|
if (level == 0)
|
||||||
{
|
{
|
||||||
|
linenr--;
|
||||||
const std::string::size_type pos1 = pos - p + 7;
|
const std::string::size_type pos1 = pos - p + 7;
|
||||||
const std::string::size_type pos2 = code.find_first_of("\"\n", pos1);
|
const std::string::size_type pos2 = code.find_first_of("\"\n", pos1);
|
||||||
f = code.substr(pos1, (pos2 == std::string::npos) ? pos2 : (pos2 - pos1));
|
f = code.substr(pos1, (pos2 == std::string::npos) ? pos2 : (pos2 - pos1));
|
||||||
|
@ -1940,10 +1959,13 @@ void Preprocessor::handleIncludes(std::string &code, const std::string &filePath
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
missingInclude(Path::toNativeSeparators(f),
|
if (!_settings->nomsg.isSuppressed("missingInclude", f, linenr))
|
||||||
linenr,
|
{
|
||||||
filename,
|
missingInclude(Path::toNativeSeparators(f),
|
||||||
headerType == UserHeader);
|
linenr,
|
||||||
|
filename,
|
||||||
|
headerType == UserHeader);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -218,6 +218,9 @@ private:
|
||||||
TEST_CASE(testPreprocessorRead4);
|
TEST_CASE(testPreprocessorRead4);
|
||||||
|
|
||||||
TEST_CASE(invalid_define); // #2605 - hang for: '#define ='
|
TEST_CASE(invalid_define); // #2605 - hang for: '#define ='
|
||||||
|
|
||||||
|
// inline suppression, missingInclude
|
||||||
|
TEST_CASE(inline_suppression_for_missing_include);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2822,6 +2825,26 @@ private:
|
||||||
std::list<std::string> paths;
|
std::list<std::string> paths;
|
||||||
preprocessor.preprocess(src, processedFile, cfg, "", paths); // don't hang
|
preprocessor.preprocess(src, processedFile, cfg, "", paths); // don't hang
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void inline_suppression_for_missing_include()
|
||||||
|
{
|
||||||
|
Settings settings;
|
||||||
|
settings._inlineSuppressions = true;
|
||||||
|
settings.addEnabled("all");
|
||||||
|
Preprocessor preprocessor(&settings, this);
|
||||||
|
|
||||||
|
std::istringstream src("// cppcheck-suppress missingInclude\n"
|
||||||
|
"#include \"missing.h\"\n"
|
||||||
|
"int x;");
|
||||||
|
std::string processedFile;
|
||||||
|
std::list<std::string> cfg;
|
||||||
|
std::list<std::string> paths;
|
||||||
|
|
||||||
|
// Don't report that the include is missing
|
||||||
|
errout.str("");
|
||||||
|
preprocessor.preprocess(src, processedFile, cfg, "test.c", paths);
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
REGISTER_TEST(TestPreprocessor)
|
REGISTER_TEST(TestPreprocessor)
|
||||||
|
|
Loading…
Reference in New Issue