From 8210435720f3b6c044d5a546c4799565d5d2e276 Mon Sep 17 00:00:00 2001 From: firewave Date: Fri, 10 Nov 2023 15:56:33 +0100 Subject: [PATCH] pass `Suppressions` separately into `CppCheckExecutor::reportSuppressions()` [skip ci] --- cli/cppcheckexecutor.cpp | 14 +++++++------- cli/cppcheckexecutor.h | 3 ++- test/testsuppressions.cpp | 6 +++--- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/cli/cppcheckexecutor.cpp b/cli/cppcheckexecutor.cpp index 3d81d360411b..06acfbe56e8b 100644 --- a/cli/cppcheckexecutor.cpp +++ b/cli/cppcheckexecutor.cpp @@ -305,9 +305,9 @@ int CppCheckExecutor::check_wrapper(CppCheck& cppcheck) return check_internal(cppcheck); } -bool CppCheckExecutor::reportSuppressions(const Settings &settings, bool unusedFunctionCheckEnabled, const std::list> &files, const std::list& fileSettings, ErrorLogger& errorLogger) { - const auto& suppressions = settings.nomsg.getSuppressions(); - if (std::any_of(suppressions.begin(), suppressions.end(), [](const Suppressions::Suppression& s) { +bool CppCheckExecutor::reportSuppressions(const Settings &settings, const Suppressions& suppressions, bool unusedFunctionCheckEnabled, const std::list> &files, const std::list& fileSettings, ErrorLogger& errorLogger) { + const auto& suppr = suppressions.getSuppressions(); + if (std::any_of(suppr.begin(), suppr.end(), [](const Suppressions::Suppression& s) { return s.errorId == "unmatchedSuppression" && s.fileName.empty() && s.lineNumber == Suppressions::Suppression::NO_LINE; })) return false; @@ -319,15 +319,15 @@ bool CppCheckExecutor::reportSuppressions(const Settings &settings, bool unusedF for (std::list>::const_iterator i = files.cbegin(); i != files.cend(); ++i) { err |= Suppressions::reportUnmatchedSuppressions( - settings.nomsg.getUnmatchedLocalSuppressions(i->first, unusedFunctionCheckEnabled), errorLogger); + suppressions.getUnmatchedLocalSuppressions(i->first, unusedFunctionCheckEnabled), errorLogger); } for (std::list::const_iterator i = fileSettings.cbegin(); i != fileSettings.cend(); ++i) { err |= Suppressions::reportUnmatchedSuppressions( - settings.nomsg.getUnmatchedLocalSuppressions(i->filename, unusedFunctionCheckEnabled), errorLogger); + suppressions.getUnmatchedLocalSuppressions(i->filename, unusedFunctionCheckEnabled), errorLogger); } } - err |= Suppressions::reportUnmatchedSuppressions(settings.nomsg.getUnmatchedGlobalSuppressions(unusedFunctionCheckEnabled), errorLogger); + err |= Suppressions::reportUnmatchedSuppressions(suppressions.getUnmatchedGlobalSuppressions(unusedFunctionCheckEnabled), errorLogger); return err; } @@ -378,7 +378,7 @@ int CppCheckExecutor::check_internal(CppCheck& cppcheck) cppcheck.analyseWholeProgram(settings.buildDir, mFiles, mFileSettings); if (settings.severity.isEnabled(Severity::information) || settings.checkConfiguration) { - const bool err = reportSuppressions(settings, cppcheck.isUnusedFunctionCheckEnabled(), mFiles, mFileSettings, *this); + const bool err = reportSuppressions(settings, settings.nomsg, cppcheck.isUnusedFunctionCheckEnabled(), mFiles, mFileSettings, *this); if (err && returnValue == 0) returnValue = settings.exitCode; } diff --git a/cli/cppcheckexecutor.h b/cli/cppcheckexecutor.h index 83d3baa7c386..818c22f42b1b 100644 --- a/cli/cppcheckexecutor.h +++ b/cli/cppcheckexecutor.h @@ -36,6 +36,7 @@ class CppCheck; class Library; class Settings; +class Suppressions; /** * This class works as an example of how CppCheck can be used in external @@ -129,7 +130,7 @@ class CppCheckExecutor : public ErrorLogger { */ bool parseFromArgs(Settings &settings, int argc, const char* const argv[]); - static bool reportSuppressions(const Settings &settings, bool unusedFunctionCheckEnabled, const std::list> &files, const std::list& fileSettings, ErrorLogger& errorLogger); + static bool reportSuppressions(const Settings &settings, const Suppressions& suppressions, bool unusedFunctionCheckEnabled, const std::list> &files, const std::list& fileSettings, ErrorLogger& errorLogger); /** * Wrapper around check_internal diff --git a/test/testsuppressions.cpp b/test/testsuppressions.cpp index 97d8ff08b179..d1b1ff3f831e 100644 --- a/test/testsuppressions.cpp +++ b/test/testsuppressions.cpp @@ -256,7 +256,7 @@ class TestSuppressions : public TestFixture { SingleExecutor executor(cppCheck, filelist, fileSettings, settings, settings.nomsg, *this); const unsigned int exitCode = executor.check(); - CppCheckExecutor::reportSuppressions(settings, false, filelist, fileSettings, *this); + CppCheckExecutor::reportSuppressions(settings, settings.nomsg, false, filelist, fileSettings, *this); return exitCode; } @@ -303,7 +303,7 @@ class TestSuppressions : public TestFixture { ThreadExecutor executor(filelist, fileSettings, settings, settings.nomsg, *this, CppCheckExecutor::executeCommand); const unsigned int exitCode = executor.check(); - CppCheckExecutor::reportSuppressions(settings, false, filelist, fileSettings, *this); + CppCheckExecutor::reportSuppressions(settings, settings.nomsg, false, filelist, fileSettings, *this); return exitCode; } @@ -351,7 +351,7 @@ class TestSuppressions : public TestFixture { ProcessExecutor executor(filelist, fileSettings, settings, settings.nomsg, *this, CppCheckExecutor::executeCommand); const unsigned int exitCode = executor.check(); - CppCheckExecutor::reportSuppressions(settings, false, filelist, fileSettings, *this); + CppCheckExecutor::reportSuppressions(settings, settings.nomsg, false, filelist, fileSettings, *this); return exitCode; }