@@ -293,35 +293,65 @@ int CppCheckExecutor::check_wrapper(const Settings& settings, Suppressions& supp
293293 return check_internal (settings, supprs);
294294}
295295
296- bool CppCheckExecutor::reportSuppressions (const Settings &settings, const SuppressionList& suppressions, bool unusedFunctionCheckEnabled, const std::list<FileWithDetails> &files, const std::list<FileSettings>& fileSettings, ErrorLogger& errorLogger) {
297- const auto & suppr = suppressions.getSuppressions ();
298- if (std::any_of (suppr.begin (), suppr.end (), [](const SuppressionList::Suppression& s) {
296+ /* *
297+ * Report unmatched suppressions
298+ * @param unmatched list of unmatched suppressions (from Settings::Suppressions::getUnmatched(Local|Global)Suppressions)
299+ * @return true is returned if errors are reported
300+ */
301+ static bool reportUnmatchedSuppressions (const std::list<SuppressionList::Suppression> &unmatched, ErrorLogger &errorLogger, const std::vector<std::string>& filters)
302+ {
303+ bool err = false ;
304+ // Report unmatched suppressions
305+ for (const SuppressionList::Suppression &s : unmatched) {
306+ bool skip = false ;
307+ for (const auto & filter : filters)
308+ {
309+ if (matchglob (filter, s.errorId ))
310+ {
311+ skip = true ;
312+ break ;
313+ }
314+ }
315+ if (skip)
316+ continue ;
317+
318+ std::list<::ErrorMessage::FileLocation> callStack;
319+ if (!s.fileName .empty ()) {
320+ callStack.emplace_back (s.fileName , s.lineNumber , 0 );
321+ }
322+ errorLogger.reportErr (::ErrorMessage (std::move (callStack), " " , Severity::information, " Unmatched suppression: " + s.errorId , " unmatchedSuppression" , Certainty::normal));
323+ err = true ;
324+ }
325+ return err;
326+ }
327+
328+ bool CppCheckExecutor::reportUnmatchedSuppressions (const Settings &settings, const SuppressionList& suppressions, const std::list<FileWithDetails> &files, const std::list<FileSettings>& fileSettings, ErrorLogger& errorLogger) {
329+ // TODO: document this
330+ const auto suppr = suppressions.getSuppressions ();
331+ if (std::any_of (suppr.cbegin (), suppr.cend (), [](const SuppressionList::Suppression& s) {
299332 return s.errorId == " unmatchedSuppression" && s.fileName .empty () && s.lineNumber == SuppressionList::Suppression::NO_LINE;
300333 }))
301334 return false ;
302335
303336 bool err = false ;
304- if (settings. useSingleJob ()) {
337+ {
305338 // the two inputs may only be used exclusively
306339 assert (!(!files.empty () && !fileSettings.empty ()));
307340
308341 for (auto i = files.cbegin (); i != files.cend (); ++i) {
309- err |= SuppressionList::reportUnmatchedSuppressions (
310- suppressions.getUnmatchedLocalSuppressions (*i, unusedFunctionCheckEnabled), errorLogger);
342+ err |= ::reportUnmatchedSuppressions (suppressions.getUnmatchedLocalSuppressions (*i), errorLogger, settings.unmatchedSuppressionFilters );
311343 }
312344
313345 for (auto i = fileSettings.cbegin (); i != fileSettings.cend (); ++i) {
314- err |= SuppressionList::reportUnmatchedSuppressions (
315- suppressions.getUnmatchedLocalSuppressions (i->file , unusedFunctionCheckEnabled), errorLogger);
346+ err |= ::reportUnmatchedSuppressions (suppressions.getUnmatchedLocalSuppressions (i->file ), errorLogger, settings.unmatchedSuppressionFilters );
316347 }
317348 }
318349 if (settings.inlineSuppressions ) {
319350 // report unmatched unusedFunction suppressions
320- err |= SuppressionList::reportUnmatchedSuppressions (
321- suppressions.getUnmatchedInlineSuppressions (unusedFunctionCheckEnabled), errorLogger);
351+ err |= ::reportUnmatchedSuppressions (suppressions.getUnmatchedInlineSuppressions (), errorLogger, settings.unmatchedSuppressionFilters );
322352 }
323353
324- err |= SuppressionList ::reportUnmatchedSuppressions (suppressions.getUnmatchedGlobalSuppressions (unusedFunctionCheckEnabled ), errorLogger);
354+ err |= ::reportUnmatchedSuppressions (suppressions.getUnmatchedGlobalSuppressions (), errorLogger, settings. unmatchedSuppressionFilters );
325355 return err;
326356}
327357
@@ -376,7 +406,7 @@ int CppCheckExecutor::check_internal(const Settings& settings, Suppressions& sup
376406 returnValue |= cppcheck.analyseWholeProgram (settings.buildDir , mFiles , mFileSettings , stdLogger.getCtuInfo ());
377407
378408 if (settings.severity .isEnabled (Severity::information) || settings.checkConfiguration ) {
379- const bool err = reportSuppressions (settings, supprs.nomsg , settings. checks . isEnabled (Checks::unusedFunction) , mFiles , mFileSettings , stdLogger);
409+ const bool err = reportUnmatchedSuppressions (settings, supprs.nomsg , mFiles , mFileSettings , stdLogger);
380410 if (err && returnValue == 0 )
381411 returnValue = settings.exitCode ;
382412 }
0 commit comments