Skip to content

Commit 8210435

Browse files
committed
pass Suppressions separately into CppCheckExecutor::reportSuppressions() [skip ci]
1 parent c36bafd commit 8210435

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

cli/cppcheckexecutor.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -305,9 +305,9 @@ 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, const std::list<FileSettings>& fileSettings, ErrorLogger& errorLogger) {
309-
const auto& suppressions = settings.nomsg.getSuppressions();
310-
if (std::any_of(suppressions.begin(), suppressions.end(), [](const Suppressions::Suppression& s) {
308+
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) {
309+
const auto& suppr = suppressions.getSuppressions();
310+
if (std::any_of(suppr.begin(), suppr.end(), [](const Suppressions::Suppression& s) {
311311
return s.errorId == "unmatchedSuppression" && s.fileName.empty() && s.lineNumber == Suppressions::Suppression::NO_LINE;
312312
}))
313313
return false;
@@ -319,15 +319,15 @@ bool CppCheckExecutor::reportSuppressions(const Settings &settings, bool unusedF
319319

320320
for (std::list<std::pair<std::string, std::size_t>>::const_iterator i = files.cbegin(); i != files.cend(); ++i) {
321321
err |= Suppressions::reportUnmatchedSuppressions(
322-
settings.nomsg.getUnmatchedLocalSuppressions(i->first, unusedFunctionCheckEnabled), errorLogger);
322+
suppressions.getUnmatchedLocalSuppressions(i->first, unusedFunctionCheckEnabled), errorLogger);
323323
}
324324

325325
for (std::list<FileSettings>::const_iterator i = fileSettings.cbegin(); i != fileSettings.cend(); ++i) {
326326
err |= Suppressions::reportUnmatchedSuppressions(
327-
settings.nomsg.getUnmatchedLocalSuppressions(i->filename, unusedFunctionCheckEnabled), errorLogger);
327+
suppressions.getUnmatchedLocalSuppressions(i->filename, unusedFunctionCheckEnabled), errorLogger);
328328
}
329329
}
330-
err |= Suppressions::reportUnmatchedSuppressions(settings.nomsg.getUnmatchedGlobalSuppressions(unusedFunctionCheckEnabled), errorLogger);
330+
err |= Suppressions::reportUnmatchedSuppressions(suppressions.getUnmatchedGlobalSuppressions(unusedFunctionCheckEnabled), errorLogger);
331331
return err;
332332
}
333333

@@ -378,7 +378,7 @@ int CppCheckExecutor::check_internal(CppCheck& cppcheck)
378378
cppcheck.analyseWholeProgram(settings.buildDir, mFiles, mFileSettings);
379379

380380
if (settings.severity.isEnabled(Severity::information) || settings.checkConfiguration) {
381-
const bool err = reportSuppressions(settings, cppcheck.isUnusedFunctionCheckEnabled(), mFiles, mFileSettings, *this);
381+
const bool err = reportSuppressions(settings, settings.nomsg, cppcheck.isUnusedFunctionCheckEnabled(), mFiles, mFileSettings, *this);
382382
if (err && returnValue == 0)
383383
returnValue = settings.exitCode;
384384
}

cli/cppcheckexecutor.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
class CppCheck;
3737
class Library;
3838
class Settings;
39+
class Suppressions;
3940

4041
/**
4142
* This class works as an example of how CppCheck can be used in external
@@ -129,7 +130,7 @@ class CppCheckExecutor : public ErrorLogger {
129130
*/
130131
bool parseFromArgs(Settings &settings, int argc, const char* const argv[]);
131132

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);
133+
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);
133134

134135
/**
135136
* Wrapper around check_internal

test/testsuppressions.cpp

Lines changed: 3 additions & 3 deletions
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, fileSettings, *this);
259+
CppCheckExecutor::reportSuppressions(settings, settings.nomsg, 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, fileSettings, *this);
306+
CppCheckExecutor::reportSuppressions(settings, settings.nomsg, 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, fileSettings, *this);
354+
CppCheckExecutor::reportSuppressions(settings, settings.nomsg, false, filelist, fileSettings, *this);
355355

356356
return exitCode;
357357
}

0 commit comments

Comments
 (0)