@@ -311,9 +311,13 @@ bool SuppressionList::updateSuppressionState(const SuppressionList::Suppression&
311311 auto foundSuppression = std::find_if (mSuppressions .begin (), mSuppressions .end (),
312312 std::bind (&Suppression::isSameParameters, &suppression, std::placeholders::_1));
313313 if (foundSuppression != mSuppressions .end ()) {
314- // Update matched state of existing global suppression
315- if (!suppression.isLocal () && suppression.matched )
316- foundSuppression->matched = suppression.matched ;
314+ // Update state of existing global suppression
315+ if (!suppression.isLocal ()) {
316+ if (suppression.checked )
317+ foundSuppression->checked = true ;
318+ if (suppression.matched )
319+ foundSuppression->matched = true ;
320+ }
317321 return true ;
318322 }
319323
@@ -373,26 +377,32 @@ bool SuppressionList::Suppression::parseComment(std::string comment, std::string
373377 return true ;
374378}
375379
376- bool SuppressionList::Suppression::isSuppressed (const SuppressionList::ErrorMessage &errmsg) const
380+ SuppressionList::Suppression::Result SuppressionList::Suppression::isSuppressed (const SuppressionList::ErrorMessage &errmsg) const
377381{
378- if (hash > 0 && hash != errmsg.hash )
379- return false ;
380- if (!errorId.empty () && !matchglob (errorId, errmsg.errorId ))
381- return false ;
382382 if (type == SuppressionList::Type::macro) {
383383 if (errmsg.macroNames .count (macroName) == 0 )
384- return false ;
384+ return Result::None;
385+ if (hash > 0 && hash != errmsg.hash )
386+ return Result::Checked;
387+ if (!errorId.empty () && !matchglob (errorId, errmsg.errorId ))
388+ return Result::Checked;
385389 } else {
386390 if (!fileName.empty () && !matchglob (fileName, errmsg.getFileName ()))
387- return false ;
391+ return Result::None ;
388392 if ((SuppressionList::Type::unique == type) && (lineNumber != NO_LINE) && (lineNumber != errmsg.lineNumber )) {
389393 if (!thisAndNextLine || lineNumber + 1 != errmsg.lineNumber )
390- return false ;
394+ return Result::None ;
391395 }
396+ if (hash > 0 && hash != errmsg.hash )
397+ return Result::Checked;
398+ // the empty check is a hack to allow wildcard suppressions on IDs to be marked as checked
399+ if (!errorId.empty () && (errmsg.errorId .empty () || !matchglob (errorId, errmsg.errorId )))
400+ return Result::Checked;
392401 if ((SuppressionList::Type::block == type) && ((errmsg.lineNumber < lineBegin) || (errmsg.lineNumber > lineEnd)))
393- return false ;
402+ return Result::Checked ;
394403 }
395404 if (!symbolName.empty ()) {
405+ bool matchedSymbol = false ;
396406 for (std::string::size_type pos = 0 ; pos < errmsg.symbolNames .size ();) {
397407 const std::string::size_type pos2 = errmsg.symbolNames .find (' \n ' ,pos);
398408 std::string symname;
@@ -403,21 +413,31 @@ bool SuppressionList::Suppression::isSuppressed(const SuppressionList::ErrorMess
403413 symname = errmsg.symbolNames .substr (pos,pos2-pos);
404414 pos = pos2+1 ;
405415 }
406- if (matchglob (symbolName, symname))
407- return true ;
416+ if (matchglob (symbolName, symname)) {
417+ matchedSymbol = true ;
418+ break ;
419+ }
408420 }
409- return false ;
421+ if (!matchedSymbol)
422+ return Result::Checked;
410423 }
411- return true ;
424+ return Result::Matched ;
412425}
413426
414427bool SuppressionList::Suppression::isMatch (const SuppressionList::ErrorMessage &errmsg)
415428{
416- if (!isSuppressed (errmsg))
429+ switch (isSuppressed (errmsg)) {
430+ case Result::None:
417431 return false ;
418- matched = true ;
419- checked = true ;
420- return true ;
432+ case Result::Checked:
433+ checked = true ;
434+ return false ;
435+ case Result::Matched:
436+ checked = true ;
437+ matched = true ;
438+ return true ;
439+ }
440+ cppcheck::unreachable ();
421441}
422442
423443// cppcheck-suppress unusedFunction - used by GUI only
@@ -525,7 +545,9 @@ std::list<SuppressionList::Suppression> SuppressionList::getUnmatchedLocalSuppre
525545 for (const Suppression &s : mSuppressions ) {
526546 if (s.isInline )
527547 continue ;
528- if (s.matched || ((s.lineNumber != Suppression::NO_LINE) && !s.checked ))
548+ if (s.matched )
549+ continue ;
550+ if ((s.lineNumber != Suppression::NO_LINE) && !s.checked )
529551 continue ;
530552 if (s.type == SuppressionList::Type::macro)
531553 continue ;
@@ -550,7 +572,9 @@ std::list<SuppressionList::Suppression> SuppressionList::getUnmatchedGlobalSuppr
550572 for (const Suppression &s : mSuppressions ) {
551573 if (s.isInline )
552574 continue ;
553- if (s.matched || ((s.lineNumber != Suppression::NO_LINE) && !s.checked ))
575+ if (s.matched )
576+ continue ;
577+ if (!s.checked && s.isWildcard ())
554578 continue ;
555579 if (s.hash > 0 )
556580 continue ;
@@ -571,6 +595,7 @@ std::list<SuppressionList::Suppression> SuppressionList::getUnmatchedInlineSuppr
571595 for (const SuppressionList::Suppression &s : SuppressionList::mSuppressions ) {
572596 if (!s.isInline )
573597 continue ;
598+ // TODO: remove this and markUnmatchedInlineSuppressionsAsChecked()?
574599 if (!s.checked )
575600 continue ;
576601 if (s.matched )
0 commit comments