Skip to content

Commit cd37df3

Browse files
committed
pass FileSettings to CppCheckExecutor::reportSuppressions()
1 parent 67c6b0c commit cd37df3

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

Diff for: cli/cppcheckexecutor.cpp

+10-2
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ int CppCheckExecutor::check_wrapper(CppCheck& cppcheck)
305305
return check_internal(cppcheck);
306306
}
307307

308-
bool CppCheckExecutor::reportSuppressions(const Settings &settings, bool unusedFunctionCheckEnabled, const std::list<std::pair<std::string, std::size_t>> &files, ErrorLogger& errorLogger) {
308+
bool CppCheckExecutor::reportSuppressions(const Settings &settings, bool unusedFunctionCheckEnabled, const std::list<std::pair<std::string, std::size_t>> &files, const std::list<FileSettings>& fileSettings, ErrorLogger& errorLogger) {
309309
const auto& suppressions = settings.nomsg.getSuppressions();
310310
if (std::any_of(suppressions.begin(), suppressions.end(), [](const Suppressions::Suppression& s) {
311311
return s.errorId == "unmatchedSuppression" && s.fileName.empty() && s.lineNumber == Suppressions::Suppression::NO_LINE;
@@ -314,10 +314,18 @@ bool CppCheckExecutor::reportSuppressions(const Settings &settings, bool unusedF
314314

315315
bool err = false;
316316
if (settings.useSingleJob()) {
317+
// the two inputs may only be used exclusively
318+
assert(!(!files.empty() && !fileSettings.empty()));
319+
317320
for (std::list<std::pair<std::string, std::size_t>>::const_iterator i = files.cbegin(); i != files.cend(); ++i) {
318321
err |= Suppressions::reportUnmatchedSuppressions(
319322
settings.nomsg.getUnmatchedLocalSuppressions(i->first, unusedFunctionCheckEnabled), errorLogger);
320323
}
324+
325+
for (std::list<FileSettings>::const_iterator i = fileSettings.cbegin(); i != fileSettings.cend(); ++i) {
326+
err |= Suppressions::reportUnmatchedSuppressions(
327+
settings.nomsg.getUnmatchedLocalSuppressions(i->filename, unusedFunctionCheckEnabled), errorLogger);
328+
}
321329
}
322330
err |= Suppressions::reportUnmatchedSuppressions(settings.nomsg.getUnmatchedGlobalSuppressions(unusedFunctionCheckEnabled), errorLogger);
323331
return err;
@@ -370,7 +378,7 @@ int CppCheckExecutor::check_internal(CppCheck& cppcheck)
370378
cppcheck.analyseWholeProgram(settings.buildDir, mFiles, mFileSettings);
371379

372380
if (settings.severity.isEnabled(Severity::information) || settings.checkConfiguration) {
373-
const bool err = reportSuppressions(settings, cppcheck.isUnusedFunctionCheckEnabled(), mFiles, *this);
381+
const bool err = reportSuppressions(settings, cppcheck.isUnusedFunctionCheckEnabled(), mFiles, mFileSettings, *this);
374382
if (err && returnValue == 0)
375383
returnValue = settings.exitCode;
376384
}

Diff for: cli/cppcheckexecutor.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ class CppCheckExecutor : public ErrorLogger {
129129
*/
130130
bool parseFromArgs(Settings &settings, int argc, const char* const argv[]);
131131

132-
static bool reportSuppressions(const Settings &settings, bool unusedFunctionCheckEnabled, const std::list<std::pair<std::string, std::size_t>> &files, ErrorLogger& errorLogger);
132+
static bool reportSuppressions(const Settings &settings, bool unusedFunctionCheckEnabled, const std::list<std::pair<std::string, std::size_t>> &files, const std::list<FileSettings>& fileSettings, ErrorLogger& errorLogger);
133133

134134
/**
135135
* Wrapper around check_internal

Diff for: test/testsuppressions.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ class TestSuppressions : public TestFixture {
256256
SingleExecutor executor(cppCheck, filelist, fileSettings, settings, settings.nomsg, *this);
257257
const unsigned int exitCode = executor.check();
258258

259-
CppCheckExecutor::reportSuppressions(settings, false, filelist, *this);
259+
CppCheckExecutor::reportSuppressions(settings, false, filelist, fileSettings, *this);
260260

261261
return exitCode;
262262
}
@@ -303,7 +303,7 @@ class TestSuppressions : public TestFixture {
303303
ThreadExecutor executor(filelist, fileSettings, settings, settings.nomsg, *this, CppCheckExecutor::executeCommand);
304304
const unsigned int exitCode = executor.check();
305305

306-
CppCheckExecutor::reportSuppressions(settings, false, filelist, *this);
306+
CppCheckExecutor::reportSuppressions(settings, false, filelist, fileSettings, *this);
307307

308308
return exitCode;
309309
}
@@ -351,7 +351,7 @@ class TestSuppressions : public TestFixture {
351351
ProcessExecutor executor(filelist, fileSettings, settings, settings.nomsg, *this, CppCheckExecutor::executeCommand);
352352
const unsigned int exitCode = executor.check();
353353

354-
CppCheckExecutor::reportSuppressions(settings, false, filelist, *this);
354+
CppCheckExecutor::reportSuppressions(settings, false, filelist, fileSettings, *this);
355355

356356
return exitCode;
357357
}

0 commit comments

Comments
 (0)