diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 26d98c0c7b4..7f281323964 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -189,8 +189,9 @@ class CppCheck::CppCheckLogger : public ErrorLogger const auto errorMessage = SuppressionList::ErrorMessage::fromErrorMessage(msg, macroNames); bool suppressed = false; + bool inlineSupressed; - if (mSuppressions.nomsg.isSuppressed(errorMessage, mUseGlobalSuppressions)) { + if (mSuppressions.nomsg.isSuppressed(errorMessage, mUseGlobalSuppressions, &inlineSupressed)) { // Safety: Report critical errors to ErrorLogger if (mSettings.safety && ErrorLogger::isCriticalErrorId(msg.id)) { mExitCode = 1; @@ -220,7 +221,7 @@ class CppCheck::CppCheckLogger : public ErrorLogger if (!mSettings.emitDuplicates && !mErrorList.emplace(std::move(errmsg)).second) return; - if (mAnalyzerInformation) + if (mAnalyzerInformation && !inlineSupressed) mAnalyzerInformation->reportErr(msg); if (suppressed) diff --git a/lib/suppressions.cpp b/lib/suppressions.cpp index b45ba151914..9f5b7d51dd5 100644 --- a/lib/suppressions.cpp +++ b/lib/suppressions.cpp @@ -472,10 +472,10 @@ bool SuppressionList::Suppression::isMatch(const SuppressionList::ErrorMessage & cppcheck::unreachable(); } -bool SuppressionList::isSuppressed(const SuppressionList::ErrorMessage &errmsg, bool global) -{ +bool SuppressionList::isSuppressed(const SuppressionList::ErrorMessage &errmsg, bool global, bool *inlineSupressed) { std::lock_guard lg(mSuppressionsSync); - + if (inlineSupressed) + *inlineSupressed = false; // TODO: handle unmatchedPolyspaceSuppression? const bool unmatchedSuppression(errmsg.errorId == "unmatchedSuppression"); bool returnValue = false; @@ -484,8 +484,11 @@ bool SuppressionList::isSuppressed(const SuppressionList::ErrorMessage &errmsg, continue; if (unmatchedSuppression && s.errorId != errmsg.errorId) continue; - if (s.isMatch(errmsg)) + if (s.isMatch(errmsg)) { returnValue = true; + if (inlineSupressed && s.isInline) + *inlineSupressed = true; + } } return returnValue; } diff --git a/lib/suppressions.h b/lib/suppressions.h index 849c972d0a7..73885a8621d 100644 --- a/lib/suppressions.h +++ b/lib/suppressions.h @@ -233,9 +233,10 @@ class CPPCHECKLIB SuppressionList { * @brief Returns true if this message should not be shown to the user. * @param errmsg error message * @param global use global suppressions + * @param inlineSupressed is true if there exists an inline suppression for this error * @return true if this error is suppressed. */ - bool isSuppressed(const ErrorMessage &errmsg, bool global = true); + bool isSuppressed(const ErrorMessage &errmsg, bool global = true, bool *inlineSupressed = nullptr); /** * @brief Returns true if this message is "explicitly" suppressed. The suppression "id" must match textually exactly.