|
42 | 42 | #endif
|
43 | 43 |
|
44 | 44 | #include <algorithm>
|
| 45 | +#include <cassert> |
45 | 46 | #include <cstdio>
|
46 | 47 | #include <cstdlib> // EXIT_SUCCESS and EXIT_FAILURE
|
47 | 48 | #include <ctime>
|
@@ -217,21 +218,29 @@ int CppCheckExecutor::check_wrapper(CppCheck& cppcheck)
|
217 | 218 | return check_internal(cppcheck);
|
218 | 219 | }
|
219 | 220 |
|
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) { |
223 | 224 | return s.errorId == "unmatchedSuppression" && s.fileName.empty() && s.lineNumber == Suppressions::Suppression::NO_LINE;
|
224 | 225 | }))
|
225 | 226 | return false;
|
226 | 227 |
|
227 | 228 | bool err = false;
|
228 | 229 | if (settings.useSingleJob()) {
|
| 230 | + // the two inputs may only be used exclusively |
| 231 | + assert(!(!files.empty() && !fileSettings.empty())); |
| 232 | + |
229 | 233 | for (std::list<std::pair<std::string, std::size_t>>::const_iterator i = files.cbegin(); i != files.cend(); ++i) {
|
230 | 234 | 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); |
232 | 241 | }
|
233 | 242 | }
|
234 |
| - err |= Suppressions::reportUnmatchedSuppressions(settings.nomsg.getUnmatchedGlobalSuppressions(unusedFunctionCheckEnabled), errorLogger); |
| 243 | + err |= Suppressions::reportUnmatchedSuppressions(suppressions.getUnmatchedGlobalSuppressions(unusedFunctionCheckEnabled), errorLogger); |
235 | 244 | return err;
|
236 | 245 | }
|
237 | 246 |
|
@@ -277,7 +286,7 @@ int CppCheckExecutor::check_internal(CppCheck& cppcheck) const
|
277 | 286 | cppcheck.analyseWholeProgram(settings.buildDir, mFiles, mFileSettings);
|
278 | 287 |
|
279 | 288 | 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); |
281 | 290 | if (err && returnValue == 0)
|
282 | 291 | returnValue = settings.exitCode;
|
283 | 292 | }
|
|
0 commit comments