From 865c0205e3a1180b8f625785dfb887052e0a695a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 23 Sep 2012 10:56:12 +0200 Subject: [PATCH] Fixed #4210 (Unmatched suppression warning emitted from disabled check) --- lib/suppressions.cpp | 15 +++++++++++++++ test/testsuppressions.cpp | 8 ++++++++ 2 files changed, 23 insertions(+) diff --git a/lib/suppressions.cpp b/lib/suppressions.cpp index 021beb72a..d49b9b88b 100644 --- a/lib/suppressions.cpp +++ b/lib/suppressions.cpp @@ -264,6 +264,9 @@ std::list Suppressions::getUnmatchedLocalSuppres { std::list r; for (std::map::const_iterator i = _suppressions.begin(); i != _suppressions.end(); ++i) { + if (i->first == "unusedFunction") + continue; // unusedFunction is not a "local" suppression + std::map >::const_iterator f = i->second._files.find(file); if (f != i->second._files.end()) { for (std::map::const_iterator l = f->second.begin(); l != f->second.end(); ++l) { @@ -280,6 +283,7 @@ std::list Suppressions::getUnmatchedGlobalSuppre { std::list r; for (std::map::const_iterator i = _suppressions.begin(); i != _suppressions.end(); ++i) { + // global suppressions.. for (std::map >::const_iterator g = i->second._globs.begin(); g != i->second._globs.end(); ++g) { for (std::map::const_iterator l = g->second.begin(); l != g->second.end(); ++l) { if (!l->second) { @@ -287,6 +291,17 @@ std::list Suppressions::getUnmatchedGlobalSuppre } } } + + // unusedFunction.. + if (i->first == "unusedFunction") { + for (std::map >::const_iterator f = i->second._files.begin(); f != i->second._files.end(); ++f) { + for (std::map::const_iterator l = f->second.begin(); l != f->second.end(); ++l) { + if (!l->second) { + r.push_back(SuppressionEntry(i->first, f->first, l->first)); + } + } + } + } } return r; } diff --git a/test/testsuppressions.cpp b/test/testsuppressions.cpp index 70a507624..c49e437d1 100644 --- a/test/testsuppressions.cpp +++ b/test/testsuppressions.cpp @@ -41,6 +41,8 @@ private: TEST_CASE(suppressionsFileNameWithExtraPath); TEST_CASE(suppressionsSettings); TEST_CASE(suppressionsMultiFile); + + TEST_CASE(inlinesuppress_unusedFunction); // #4210 - unusedFunction } void suppressionsBadId1() { @@ -311,6 +313,12 @@ private: ASSERT_EQUALS("", errout.str()); } + void inlinesuppress_unusedFunction() { // #4210 - wrong report of "unmatchedSuppression" for "unusedFunction" + Suppressions suppressions; + suppressions.addSuppression("unusedFunction", "test.c", 3U); + ASSERT_EQUALS(true, suppressions.getUnmatchedLocalSuppressions("test.c").empty()); + ASSERT_EQUALS(false, suppressions.getUnmatchedGlobalSuppressions().empty()); + } }; REGISTER_TEST(TestSuppressions)