Allow suppressing all warnings (using *) for specified file or files

This commit is contained in:
Greg Hewgill 2011-03-10 22:00:48 +13:00
parent 1ec6a642dc
commit 256e7dee21
4 changed files with 45 additions and 10 deletions

View File

@ -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;

View File

@ -309,6 +309,7 @@ Directory name is matched to all parts of the path.</para>
<listitem>
<para>Suppress a specific warning. The format of &lt;spec&gt; 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 ?.</para>
</listitem>
</varlistentry>

View File

@ -384,7 +384,8 @@ gui/test.cpp,16,error,mismatchAllocDealloc,Mismatching allocation and deallocati
<para>The <literal>error id</literal> is the id that you want to suppress.
The easiest way to get it is to use the <literal>--xml</literal> command
line flag. Copy and paste the <literal>id</literal> string from the XML
output.</para>
output. This may be * to suppress all warnings (for a specified file or
files).</para>
<para>The <literal>filename</literal> may include the wildcard characters
* or ?, which match any sequence of characters or any single character

View File

@ -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"