Skip to content

Commit b2e0b3b

Browse files
authored
refs #12171 - start generating unmatched suppressions with FileSettings / improved TestSuppressions / some cleanups (#5827)
1 parent 615e4c0 commit b2e0b3b

File tree

3 files changed

+250
-85
lines changed

3 files changed

+250
-85
lines changed

cli/cppcheckexecutor.cpp

+15-6
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#endif
4343

4444
#include <algorithm>
45+
#include <cassert>
4546
#include <cstdio>
4647
#include <cstdlib> // EXIT_SUCCESS and EXIT_FAILURE
4748
#include <ctime>
@@ -217,21 +218,29 @@ int CppCheckExecutor::check_wrapper(CppCheck& cppcheck)
217218
return check_internal(cppcheck);
218219
}
219220

220-
bool CppCheckExecutor::reportSuppressions(const Settings &settings, bool unusedFunctionCheckEnabled, const std::list<std::pair<std::string, std::size_t>> &files, ErrorLogger& errorLogger) {
221-
const auto& suppressions = settings.nomsg.getSuppressions();
222-
if (std::any_of(suppressions.begin(), suppressions.end(), [](const Suppressions::Suppression& s) {
221+
bool CppCheckExecutor::reportSuppressions(const Settings &settings, const Suppressions& suppressions, bool unusedFunctionCheckEnabled, const std::list<std::pair<std::string, std::size_t>> &files, const std::list<FileSettings>& fileSettings, ErrorLogger& errorLogger) {
222+
const auto& suppr = suppressions.getSuppressions();
223+
if (std::any_of(suppr.begin(), suppr.end(), [](const Suppressions::Suppression& s) {
223224
return s.errorId == "unmatchedSuppression" && s.fileName.empty() && s.lineNumber == Suppressions::Suppression::NO_LINE;
224225
}))
225226
return false;
226227

227228
bool err = false;
228229
if (settings.useSingleJob()) {
230+
// the two inputs may only be used exclusively
231+
assert(!(!files.empty() && !fileSettings.empty()));
232+
229233
for (std::list<std::pair<std::string, std::size_t>>::const_iterator i = files.cbegin(); i != files.cend(); ++i) {
230234
err |= Suppressions::reportUnmatchedSuppressions(
231-
settings.nomsg.getUnmatchedLocalSuppressions(i->first, unusedFunctionCheckEnabled), errorLogger);
235+
suppressions.getUnmatchedLocalSuppressions(i->first, unusedFunctionCheckEnabled), errorLogger);
236+
}
237+
238+
for (std::list<FileSettings>::const_iterator i = fileSettings.cbegin(); i != fileSettings.cend(); ++i) {
239+
err |= Suppressions::reportUnmatchedSuppressions(
240+
suppressions.getUnmatchedLocalSuppressions(i->filename, unusedFunctionCheckEnabled), errorLogger);
232241
}
233242
}
234-
err |= Suppressions::reportUnmatchedSuppressions(settings.nomsg.getUnmatchedGlobalSuppressions(unusedFunctionCheckEnabled), errorLogger);
243+
err |= Suppressions::reportUnmatchedSuppressions(suppressions.getUnmatchedGlobalSuppressions(unusedFunctionCheckEnabled), errorLogger);
235244
return err;
236245
}
237246

@@ -277,7 +286,7 @@ int CppCheckExecutor::check_internal(CppCheck& cppcheck) const
277286
cppcheck.analyseWholeProgram(settings.buildDir, mFiles, mFileSettings);
278287

279288
if (settings.severity.isEnabled(Severity::information) || settings.checkConfiguration) {
280-
const bool err = reportSuppressions(settings, cppcheck.isUnusedFunctionCheckEnabled(), mFiles, *mStdLogger);
289+
const bool err = reportSuppressions(settings, settings.nomsg, cppcheck.isUnusedFunctionCheckEnabled(), mFiles, mFileSettings, *mStdLogger);
281290
if (err && returnValue == 0)
282291
returnValue = settings.exitCode;
283292
}

cli/cppcheckexecutor.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
class CppCheck;
3232
class Settings;
3333
class ErrorLogger;
34+
class Suppressions;
3435

3536
/**
3637
* This class works as an example of how CppCheck can be used in external
@@ -81,7 +82,7 @@ class CppCheckExecutor {
8182

8283
protected:
8384

84-
static bool reportSuppressions(const Settings &settings, bool unusedFunctionCheckEnabled, const std::list<std::pair<std::string, std::size_t>> &files, ErrorLogger& errorLogger);
85+
static bool reportSuppressions(const Settings &settings, const Suppressions& suppressions, bool unusedFunctionCheckEnabled, const std::list<std::pair<std::string, std::size_t>> &files, const std::list<FileSettings>& fileSettings, ErrorLogger& errorLogger);
8586

8687
/**
8788
* Wrapper around check_internal

0 commit comments

Comments
 (0)