Fixed #4733 (defective unusedStructMember warning)
This commit is contained in:
parent
5c3315db7a
commit
2eca0a93a7
|
@ -555,9 +555,20 @@ std::string Preprocessor::removeComments(const std::string &str, const std::stri
|
|||
// Add any pending inline suppressions that have accumulated.
|
||||
if (!suppressionIDs.empty()) {
|
||||
if (_settings != NULL) {
|
||||
// Relative filename
|
||||
std::string relativeFilename(filename);
|
||||
if (_settings->_relativePaths) {
|
||||
for (std::size_t j = 0U; j < _settings->_basePaths.size(); ++j) {
|
||||
const std::string bp = _settings->_basePaths[j] + "/";
|
||||
if (relativeFilename.compare(0,bp.size(),bp)==0) {
|
||||
relativeFilename = relativeFilename.substr(bp.size());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add the suppressions.
|
||||
for (std::size_t j = 0; j < suppressionIDs.size(); ++j) {
|
||||
const std::string errmsg(_settings->nomsg.addSuppression(suppressionIDs[j], filename, lineno));
|
||||
const std::string errmsg(_settings->nomsg.addSuppression(suppressionIDs[j], relativeFilename, lineno));
|
||||
if (!errmsg.empty()) {
|
||||
writeError(filename, lineno, _errorLogger, "cppcheckError", errmsg);
|
||||
}
|
||||
|
|
|
@ -44,6 +44,7 @@ private:
|
|||
TEST_CASE(suppressionsPathSeparator);
|
||||
|
||||
TEST_CASE(inlinesuppress_unusedFunction); // #4210 - unusedFunction
|
||||
TEST_CASE(suppressionWithRelativePaths); // #4733
|
||||
}
|
||||
|
||||
void suppressionsBadId1() const {
|
||||
|
@ -328,6 +329,28 @@ private:
|
|||
ASSERT_EQUALS(true, suppressions.getUnmatchedLocalSuppressions("test.c").empty());
|
||||
ASSERT_EQUALS(false, suppressions.getUnmatchedGlobalSuppressions().empty());
|
||||
}
|
||||
|
||||
void suppressionWithRelativePaths() {
|
||||
// Clear the error log
|
||||
errout.str("");
|
||||
|
||||
CppCheck cppCheck(*this, true);
|
||||
Settings& settings = cppCheck.settings();
|
||||
settings.addEnabled("style");
|
||||
settings._inlineSuppressions = true;
|
||||
settings._relativePaths = true;
|
||||
settings._basePaths.push_back("/somewhere");
|
||||
const char code[] =
|
||||
"struct Point\n"
|
||||
"{\n"
|
||||
" // cppcheck-suppress unusedStructMember\n"
|
||||
" int x;\n"
|
||||
" // cppcheck-suppress unusedStructMember\n"
|
||||
" int y;\n"
|
||||
"};";
|
||||
cppCheck.check("/somewhere/test.cpp", code);
|
||||
ASSERT_EQUALS("",errout.str());
|
||||
}
|
||||
};
|
||||
|
||||
REGISTER_TEST(TestSuppressions)
|
||||
|
|
Loading…
Reference in New Issue