diff --git a/lib/settings.cpp b/lib/settings.cpp
index 2aeeb6c1a..4a0d7dcd9 100644
--- a/lib/settings.cpp
+++ b/lib/settings.cpp
@@ -281,15 +281,18 @@ std::string Settings::Suppressions::addSuppression(const std::string &errorId, c
{
return "Failed to add suppression. No id.";
}
- for (std::string::size_type pos = 0; pos < errorId.length(); ++pos)
+ if (errorId != "*")
{
- if (errorId[pos] < 0 || !std::isalnum(errorId[pos]))
+ for (std::string::size_type pos = 0; pos < errorId.length(); ++pos)
{
- return "Failed to add suppression. Invalid id \"" + errorId + "\"";
- }
- if (pos == 0 && std::isdigit(errorId[pos]))
- {
- return "Failed to add suppression. Invalid id \"" + errorId + "\"";
+ if (errorId[pos] < 0 || !std::isalnum(errorId[pos]))
+ {
+ return "Failed to add suppression. Invalid id \"" + errorId + "\"";
+ }
+ if (pos == 0 && std::isdigit(errorId[pos]))
+ {
+ return "Failed to add suppression. Invalid id \"" + errorId + "\"";
+ }
}
}
@@ -298,6 +301,10 @@ std::string Settings::Suppressions::addSuppression(const std::string &errorId, c
bool Settings::Suppressions::isSuppressed(const std::string &errorId, const std::string &file, unsigned int line)
{
+ if (errorId != "unmatchedSuppression" && _suppressions.find("*") != _suppressions.end())
+ if (_suppressions["*"].isSuppressed(file, line))
+ return true;
+
if (_suppressions.find(errorId) == _suppressions.end())
return false;
@@ -306,6 +313,10 @@ bool Settings::Suppressions::isSuppressed(const std::string &errorId, const std:
bool Settings::Suppressions::isSuppressedLocal(const std::string &errorId, const std::string &file, unsigned int line)
{
+ if (errorId != "unmatchedSuppression" && _suppressions.find("*") != _suppressions.end())
+ if (_suppressions["*"].isSuppressedLocal(file, line))
+ return true;
+
if (_suppressions.find(errorId) == _suppressions.end())
return false;
diff --git a/man/cppcheck.1.xml b/man/cppcheck.1.xml
index d0aae70a0..88536f431 100644
--- a/man/cppcheck.1.xml
+++ b/man/cppcheck.1.xml
@@ -309,6 +309,7 @@ Directory name is matched to all parts of the path.
Suppress a specific warning. The format of <spec> is: [error id]:[filename]:[line].
The [filename] and [line] are optional.
+ [error id] may be * to suppress all warnings (for a specified file or files).
[filename] may contain the wildcard characters * or ?.
diff --git a/man/manual.docbook b/man/manual.docbook
index c3c16bb61..27cdb89fe 100644
--- a/man/manual.docbook
+++ b/man/manual.docbook
@@ -384,7 +384,8 @@ gui/test.cpp,16,error,mismatchAllocDealloc,Mismatching allocation and deallocati
The error id is the id that you want to suppress.
The easiest way to get it is to use the --xml command
line flag. Copy and paste the id string from the XML
- output.
+ output. This may be * to suppress all warnings (for a specified file or
+ files).
The filename may include the wildcard characters
* or ?, which match any sequence of characters or any single character
diff --git a/test/testsuppressions.cpp b/test/testsuppressions.cpp
index e26a7042d..323651f3f 100644
--- a/test/testsuppressions.cpp
+++ b/test/testsuppressions.cpp
@@ -48,7 +48,10 @@ private:
Settings settings;
settings._inlineSuppressions = true;
if (!suppression.empty())
- settings.nomsg.addSuppressionLine(suppression);
+ {
+ std::string r = settings.nomsg.addSuppressionLine(suppression);
+ ASSERT_EQUALS("", r);
+ }
CppCheck cppCheck(*this, true);
cppCheck.settings(settings);
@@ -75,7 +78,10 @@ private:
settings._jobs = 1;
settings._inlineSuppressions = true;
if (!suppression.empty())
- settings.nomsg.addSuppressionLine(suppression);
+ {
+ std::string r = settings.nomsg.addSuppressionLine(suppression);
+ ASSERT_EQUALS("", r);
+ }
ThreadExecutor executor(filenames, settings, *this);
for (unsigned int i = 0; i < filenames.size(); ++i)
executor.addFileContent(filenames[i], code);
@@ -147,6 +153,22 @@ private:
"uninitvar:test.cpp");
ASSERT_EQUALS("[test.cpp]: (information) Unmatched suppression: uninitvar\n", errout.str());
+ // suppress all for this file only
+ (this->*check)("void f() {\n"
+ " int a;\n"
+ " a++;\n"
+ "}\n",
+ "*:test.cpp");
+ ASSERT_EQUALS("", errout.str());
+
+ // suppress all for this file only, without error present
+ (this->*check)("void f() {\n"
+ " int a;\n"
+ " b++;\n"
+ "}\n",
+ "*:test.cpp");
+ ASSERT_EQUALS("[test.cpp]: (information) Unmatched suppression: *\n", errout.str());
+
// suppress uninitvar for this file and line
(this->*check)("void f() {\n"
" int a;\n"