Skip to content

Commit 6f2879a

Browse files
authored
errorlogger.cpp: Handle empty file-name like "*" (unmatchedSuppression) (#2440)
Using "--suppress=unmatchedSuppression" did not suppress the error-id in all files, one needed to specify "*" as file-name. This commit also allows empty file-names to suppress "unmatchedSuppression", not only "*" or the exact file-name. The manual uses the following example for suppressions specified in a file: // suppress all uninitvar errors in all files uninitvar This example suggests that no "*" has to be used to get suppression in all files. I think that the command line parameter should work in the same way.
1 parent ad2f713 commit 6f2879a

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

lib/errorlogger.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ bool ErrorLogger::reportUnmatchedSuppressions(const std::list<Suppressions::Supp
564564
bool suppressed = false;
565565
for (const Suppressions::Suppression &s2 : unmatched) {
566566
if (s2.errorId == "unmatchedSuppression") {
567-
if ((s2.fileName == "*" || s2.fileName == s.fileName) &&
567+
if ((s2.fileName.empty() || s2.fileName == "*" || s2.fileName == s.fileName) &&
568568
(s2.lineNumber == Suppressions::Suppression::NO_LINE || s2.lineNumber == s.lineNumber)) {
569569
suppressed = true;
570570
break;

test/testerrorlogger.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,14 @@ class TestErrorLogger : public TestFixture {
325325
reportUnmatchedSuppressions(suppressions);
326326
ASSERT_EQUALS("", errout.str());
327327

328+
// suppress all unmatchedSuppression (corresponds to "--suppress=unmatchedSuppression")
329+
errout.str("");
330+
suppressions.clear();
331+
suppressions.emplace_back("abc", "a.c", 10U);
332+
suppressions.emplace_back("unmatchedSuppression", "", Suppressions::Suppression::NO_LINE);
333+
reportUnmatchedSuppressions(suppressions);
334+
ASSERT_EQUALS("", errout.str());
335+
328336
// suppress all unmatchedSuppression in a.c
329337
errout.str("");
330338
suppressions.clear();

0 commit comments

Comments
 (0)