Skip to content

Commit 9352b8c

Browse files
committed
pass FileSettings to CppCheckExecutor::reportSuppressions()
1 parent 74b2d3c commit 9352b8c

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

cli/cppcheckexecutor.cpp

Lines changed: 11 additions & 2 deletions
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,7 +218,7 @@ 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+
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) {
221222
const auto& suppressions = settings.nomsg.getSuppressions();
222223
if (std::any_of(suppressions.begin(), suppressions.end(), [](const Suppressions::Suppression& s) {
223224
return s.errorId == "unmatchedSuppression" && s.fileName.empty() && s.lineNumber == Suppressions::Suppression::NO_LINE;
@@ -226,10 +227,18 @@ bool CppCheckExecutor::reportSuppressions(const Settings &settings, bool unusedF
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(
231235
settings.nomsg.getUnmatchedLocalSuppressions(i->first, unusedFunctionCheckEnabled), errorLogger);
232236
}
237+
238+
for (std::list<FileSettings>::const_iterator i = fileSettings.cbegin(); i != fileSettings.cend(); ++i) {
239+
err |= Suppressions::reportUnmatchedSuppressions(
240+
settings.nomsg.getUnmatchedLocalSuppressions(i->filename, unusedFunctionCheckEnabled), errorLogger);
241+
}
233242
}
234243
err |= Suppressions::reportUnmatchedSuppressions(settings.nomsg.getUnmatchedGlobalSuppressions(unusedFunctionCheckEnabled), errorLogger);
235244
return err;
@@ -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, cppcheck.isUnusedFunctionCheckEnabled(), mFiles, mFileSettings, *mStdLogger);
281290
if (err && returnValue == 0)
282291
returnValue = settings.exitCode;
283292
}

cli/cppcheckexecutor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class CppCheckExecutor {
8181

8282
protected:
8383

84-
static bool reportSuppressions(const Settings &settings, bool unusedFunctionCheckEnabled, const std::list<std::pair<std::string, std::size_t>> &files, ErrorLogger& errorLogger);
84+
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);
8585

8686
/**
8787
* Wrapper around check_internal

test/testsuppressions.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ class TestSuppressions : public TestFixture {
265265
SingleExecutor executor(cppCheck, filelist, fileSettings, settings, settings.nomsg, *this);
266266
const unsigned int exitCode = executor.check();
267267

268-
CppCheckExecutor::reportSuppressions(settings, false, filelist, *this);
268+
CppCheckExecutor::reportSuppressions(settings, false, filelist, fileSettings, *this);
269269

270270
return exitCode;
271271
}
@@ -312,7 +312,7 @@ class TestSuppressions : public TestFixture {
312312
ThreadExecutor executor(filelist, fileSettings, settings, settings.nomsg, *this, CppCheckExecutor::executeCommand);
313313
const unsigned int exitCode = executor.check();
314314

315-
CppCheckExecutor::reportSuppressions(settings, false, filelist, *this);
315+
CppCheckExecutor::reportSuppressions(settings, false, filelist, fileSettings, *this);
316316

317317
return exitCode;
318318
}
@@ -360,7 +360,7 @@ class TestSuppressions : public TestFixture {
360360
ProcessExecutor executor(filelist, fileSettings, settings, settings.nomsg, *this, CppCheckExecutor::executeCommand);
361361
const unsigned int exitCode = executor.check();
362362

363-
CppCheckExecutor::reportSuppressions(settings, false, filelist, *this);
363+
CppCheckExecutor::reportSuppressions(settings, false, filelist, fileSettings, *this);
364364

365365
return exitCode;
366366
}

0 commit comments

Comments
 (0)