Allow suppressing all warnings (using *) for specified file or files
This commit is contained in:
parent
1ec6a642dc
commit
256e7dee21
|
@ -281,15 +281,18 @@ std::string Settings::Suppressions::addSuppression(const std::string &errorId, c
|
||||||
{
|
{
|
||||||
return "Failed to add suppression. No id.";
|
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 (errorId[pos] < 0 || !std::isalnum(errorId[pos]))
|
||||||
}
|
{
|
||||||
if (pos == 0 && std::isdigit(errorId[pos]))
|
return "Failed to add suppression. Invalid id \"" + errorId + "\"";
|
||||||
{
|
}
|
||||||
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)
|
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())
|
if (_suppressions.find(errorId) == _suppressions.end())
|
||||||
return false;
|
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)
|
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())
|
if (_suppressions.find(errorId) == _suppressions.end())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
|
@ -309,6 +309,7 @@ Directory name is matched to all parts of the path.</para>
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>Suppress a specific warning. The format of <spec> is: [error id]:[filename]:[line].
|
<para>Suppress a specific warning. The format of <spec> is: [error id]:[filename]:[line].
|
||||||
The [filename] and [line] are optional.
|
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>
|
[filename] may contain the wildcard characters * or ?.</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
|
@ -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.
|
<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
|
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
|
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
|
<para>The <literal>filename</literal> may include the wildcard characters
|
||||||
* or ?, which match any sequence of characters or any single character
|
* or ?, which match any sequence of characters or any single character
|
||||||
|
|
|
@ -48,7 +48,10 @@ private:
|
||||||
Settings settings;
|
Settings settings;
|
||||||
settings._inlineSuppressions = true;
|
settings._inlineSuppressions = true;
|
||||||
if (!suppression.empty())
|
if (!suppression.empty())
|
||||||
settings.nomsg.addSuppressionLine(suppression);
|
{
|
||||||
|
std::string r = settings.nomsg.addSuppressionLine(suppression);
|
||||||
|
ASSERT_EQUALS("", r);
|
||||||
|
}
|
||||||
|
|
||||||
CppCheck cppCheck(*this, true);
|
CppCheck cppCheck(*this, true);
|
||||||
cppCheck.settings(settings);
|
cppCheck.settings(settings);
|
||||||
|
@ -75,7 +78,10 @@ private:
|
||||||
settings._jobs = 1;
|
settings._jobs = 1;
|
||||||
settings._inlineSuppressions = true;
|
settings._inlineSuppressions = true;
|
||||||
if (!suppression.empty())
|
if (!suppression.empty())
|
||||||
settings.nomsg.addSuppressionLine(suppression);
|
{
|
||||||
|
std::string r = settings.nomsg.addSuppressionLine(suppression);
|
||||||
|
ASSERT_EQUALS("", r);
|
||||||
|
}
|
||||||
ThreadExecutor executor(filenames, settings, *this);
|
ThreadExecutor executor(filenames, settings, *this);
|
||||||
for (unsigned int i = 0; i < filenames.size(); ++i)
|
for (unsigned int i = 0; i < filenames.size(); ++i)
|
||||||
executor.addFileContent(filenames[i], code);
|
executor.addFileContent(filenames[i], code);
|
||||||
|
@ -147,6 +153,22 @@ private:
|
||||||
"uninitvar:test.cpp");
|
"uninitvar:test.cpp");
|
||||||
ASSERT_EQUALS("[test.cpp]: (information) Unmatched suppression: uninitvar\n", errout.str());
|
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
|
// suppress uninitvar for this file and line
|
||||||
(this->*check)("void f() {\n"
|
(this->*check)("void f() {\n"
|
||||||
" int a;\n"
|
" int a;\n"
|
||||||
|
|
Loading…
Reference in New Issue