* Get list of unmatchedSuppression errors * @param unmatched list of unmatched suppressions * @param filters a list of (globbed) IDs to filter out * @return vector of unmatchedSuppression errors */
| 302 | * @return vector of unmatchedSuppression errors |
| 303 | */ |
| 304 | static std::vector<ErrorMessage> getUnmatchedSuppressions(const std::list<SuppressionList::Suppression> &unmatched, const std::vector<std::string>& filters) |
| 305 | { |
| 306 | std::vector<ErrorMessage> errors; |
| 307 | |
| 308 | // Report unmatched suppressions |
| 309 | for (const SuppressionList::Suppression &s : unmatched) { |
| 310 | // check if this unmatched suppression is suppressed |
| 311 | bool suppressed = false; |
| 312 | for (const SuppressionList::Suppression &s2 : unmatched) { |
| 313 | if (s2.errorId == "unmatchedSuppression") { // TODO: handle unmatchedPolyspaceSuppression? |
| 314 | if ((s2.fileName.empty() || s2.fileName == "*" || s2.fileName == s.fileName) && |
| 315 | (s2.lineNumber == SuppressionList::Suppression::NO_LINE || s2.lineNumber == s.lineNumber)) { |
| 316 | suppressed = true; |
| 317 | break; |
| 318 | } |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | if (suppressed) |
| 323 | continue; |
| 324 | |
| 325 | const bool skip = std::any_of(filters.cbegin(), filters.cend(), [&s](const std::string& filter) { |
| 326 | return matchglob(filter, s.errorId); |
| 327 | }); |
| 328 | if (skip) |
| 329 | continue; |
| 330 | |
| 331 | std::list<ErrorMessage::FileLocation> callStack; |
| 332 | if (!s.fileName.empty()) { |
| 333 | callStack.emplace_back(s.fileName, s.lineNumber == -1 ? 0 : s.lineNumber, s.column); // TODO: get rid of s.lineNumber == -1 hack |
| 334 | } |
| 335 | const std::string unmatchedSuppressionId = s.isPolyspace ? "unmatchedPolyspaceSuppression" : "unmatchedSuppression"; |
| 336 | errors.emplace_back(std::move(callStack), "", Severity::information, "Unmatched suppression: " + s.errorId, unmatchedSuppressionId, Certainty::normal); |
| 337 | } |
| 338 | |
| 339 | return errors; |
| 340 | } |
| 341 | |
| 342 | bool CppCheckExecutor::reportUnmatchedSuppressions(const Settings &settings, const SuppressionList& suppressions, const std::list<FileWithDetails> &files, const std::list<FileSettings>& fileSettings, ErrorLogger& errorLogger) { |
| 343 | // the two inputs may only be used exclusively |
no test coverage detected