Skip to content

Commit 186fd2f

Browse files
committed
refs #14702 - report unmatched suppressions for included files [skip ci]
1 parent c92a7bd commit 186fd2f

3 files changed

Lines changed: 4 additions & 81 deletions

File tree

cli/cppcheckexecutor.cpp

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -385,36 +385,14 @@ bool CppCheckExecutor::reportUnmatchedSuppressions(const Settings &settings, con
385385

386386
bool err = false;
387387

388-
for (auto i = files.cbegin(); i != files.cend(); ++i) {
389-
const std::vector<ErrorMessage> errors = getUnmatchedSuppressions(supprlist.getUnmatchedLocalSuppressions(*i), settings.unmatchedSuppressionFilters);
390-
err |= reportErrorsFn(i->spath(), i->fsFileId(), errors);
391-
}
392-
393-
for (auto i = fileSettings.cbegin(); i != fileSettings.cend(); ++i) {
394-
const std::vector<ErrorMessage> errors = getUnmatchedSuppressions(supprlist.getUnmatchedLocalSuppressions(i->file), settings.unmatchedSuppressionFilters);
395-
err |= reportErrorsFn(i->file.spath(), i->file.fsFileId(), errors);
396-
}
397-
398-
if (settings.inlineSuppressions) {
399-
const std::vector<ErrorMessage> errors = getUnmatchedSuppressions(supprlist.getUnmatchedInlineSuppressions(), settings.unmatchedSuppressionFilters);
400-
for (const auto& errmsg : errors) {
401-
std::string sourcefile;
402-
if (!errmsg.callStack.empty())
403-
sourcefile = errmsg.callStack.cbegin()->getfile(false); // TODO: simplify path?
404-
err |= reportErrorsFn(sourcefile, 0, {errmsg});
405-
}
406-
}
407-
408-
const std::vector<ErrorMessage> errors = getUnmatchedSuppressions(supprlist.getUnmatchedGlobalSuppressions(), settings.unmatchedSuppressionFilters);
388+
const std::vector<ErrorMessage> errors = getUnmatchedSuppressions(supprlist.getUnmatchedSuppressions(), settings.unmatchedSuppressionFilters);
409389
for (const auto& errmsg : errors) {
410390
std::string sourcefile;
411391
if (!errmsg.callStack.empty())
412392
sourcefile = errmsg.callStack.cbegin()->getfile(false); // TODO: simplify path?
413393
err |= reportErrorsFn(sourcefile, 0, {errmsg});
414394
}
415395

416-
// TODO: report unmatched suppressions for included files
417-
418396
return err;
419397
}
420398

lib/suppressions.cpp

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -555,32 +555,7 @@ void SuppressionList::dump(std::ostream & out, const std::string& filePath) cons
555555
out << " </suppressions>" << std::endl;
556556
}
557557

558-
std::list<SuppressionList::Suppression> SuppressionList::getUnmatchedLocalSuppressions(const FileWithDetails &file) const
559-
{
560-
std::lock_guard<std::mutex> lg(mSuppressionsSync);
561-
562-
std::list<Suppression> result;
563-
for (const Suppression &s : mSuppressions) {
564-
if (s.isInline)
565-
continue;
566-
if (s.matched)
567-
continue;
568-
if ((s.lineNumber != Suppression::NO_LINE) && !s.checked)
569-
continue;
570-
if (s.type == SuppressionList::Type::macro)
571-
continue;
572-
if (s.hash > 0)
573-
continue;
574-
if (s.errorId == ID_CHECKERSREPORT)
575-
continue;
576-
if (!s.isLocal() || !PathMatch::match(s.fileName, file.spath()))
577-
continue;
578-
result.push_back(s);
579-
}
580-
return result;
581-
}
582-
583-
std::list<SuppressionList::Suppression> SuppressionList::getUnmatchedGlobalSuppressions() const
558+
std::list<SuppressionList::Suppression> SuppressionList::getUnmatchedSuppressions() const
584559
{
585560
std::lock_guard<std::mutex> lg(mSuppressionsSync);
586561

@@ -603,24 +578,6 @@ std::list<SuppressionList::Suppression> SuppressionList::getUnmatchedGlobalSuppr
603578
return result;
604579
}
605580

606-
std::list<SuppressionList::Suppression> SuppressionList::getUnmatchedInlineSuppressions() const
607-
{
608-
std::list<SuppressionList::Suppression> result;
609-
for (const SuppressionList::Suppression &s : SuppressionList::mSuppressions) {
610-
if (!s.isInline)
611-
continue;
612-
// TODO: remove this and markUnmatchedInlineSuppressionsAsChecked()?
613-
if (!s.checked)
614-
continue;
615-
if (s.matched)
616-
continue;
617-
if (s.hash > 0)
618-
continue;
619-
result.push_back(s);
620-
}
621-
return result;
622-
}
623-
624581
std::list<SuppressionList::Suppression> SuppressionList::getSuppressions() const
625582
{
626583
std::lock_guard<std::mutex> lg(mSuppressionsSync);

lib/suppressions.h

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -259,22 +259,10 @@ class CPPCHECKLIB SuppressionList {
259259
void dump(std::ostream &out, const std::string& filePath = {}) const;
260260

261261
/**
262-
* @brief Returns list of unmatched local (per-file) suppressions.
262+
* @brief Returns list of unmatched suppressions.
263263
* @return list of unmatched suppressions
264264
*/
265-
std::list<Suppression> getUnmatchedLocalSuppressions(const FileWithDetails &file) const;
266-
267-
/**
268-
* @brief Returns list of unmatched global (glob pattern) suppressions.
269-
* @return list of unmatched suppressions
270-
*/
271-
std::list<Suppression> getUnmatchedGlobalSuppressions() const;
272-
273-
/**
274-
* @brief Returns list of unmatched inline suppressions.
275-
* @return list of unmatched suppressions
276-
*/
277-
std::list<Suppression> getUnmatchedInlineSuppressions() const;
265+
std::list<Suppression> getUnmatchedSuppressions() const;
278266

279267
/**
280268
* @brief Returns list of all suppressions.

0 commit comments

Comments
 (0)