This topic explains how to prevent C++test from reporting specific static analysis violations (e.g., when you generally follow a rule, but decide to ignore that rule in an isolated number of exceptional situations). Suppression schemes can be entered in the GUI or defined directly in the source code.
Sections include:
See Suppressions.
To suppress a static analysis task that is shown in the Quality Tasks view:
The task will then be "suppressed" and removed from the Quality Tasks view. A suppression entry will be added to the Suppressions view or directly to the source code (depending on selected mode). If the same static analysis violation is found in subsequent tests of this project, it will be reported in the Suppressions view, but not in the Quality Tasks view.
Team suppressions (as opposed to in-code suppressions) are message-based and not rule-based. Suppressions prevent the reporting of a specific static analysis task (e.g., fix the violation of rule X that occurs in line Y); they do not prevent the reporting of all violations of a rule. |
When suppressions are defined in source code:
There are two ways to define suppressions in source code:
C++test allows you to define suppressions directly in the source code, using the following directives embedded in C or C++ style comments:
parasoft-suppress <ruleid> [<ruleid> ...] ["<comment>"]:
Creates a suppression for the current line only (line with suppression directive)parasoft off
: Suppresses the reporting of all static analysis violations that occur between this line of code and the end of the file.parasoft on:
Unsuppresses the reporting of all static analysis violations that occur between this line of code and the end of the file.parasoft suppress/unsuppress [line <linewildcard>][class <classnamewildcard>][file <filenamewildcard>] [item <ruleid>][type <severity>] [reason <comment>]:
line *, line 10, line 50-*
class MyClass, class *
file *example.cpp, file *ex*.cpp
item SECURITY-02
type SV
reason "Not relevant to my code."
line, class, file
, etc.) can be combined together by separating each entry with a space (for example, item * class MyClass line 10-*).
<filenamewildcard>
must be specified as an absolute path to a file.Example A:/* parasoft suppress item SECURITY-02 */
This suppresses reporting of violation SECURITY-02 for the current file, starting from the line where the suppression is located.
Example B:/* parasoft unsuppress item * class MyClass line 10-* */
This unsuppresses all items for class MyClass
in the current file starting from line 10.
Example C:/* parasoft unsuppress item SECURITY-02 file *example.cpp */
This unsuppresses the item SECURITY-02 in any file that is in the current compilation unit and has a file path that matches the *example.cpp file name pattern.
Example D:/* parasoft suppress all */
This suppresses all messages in the current file starting from the line where this directive was entered.
Example E:void foo(); /* parasoft-suppress SECURITY-02 */
void bar(); // parasoft-suppress SECURITY-03 "Not relevant to my code."
This suppresses item SECURITY-02 on the line with "foo" declaration and item SECURITY-03 on the line with "bar" declaration with the reason "Not relevant to my code."
Example F:/* parasoft off */
/* parasoft unsuppress line 30-45 */
This suppresses everything, then unsuppress lines 30 to 45.
item
is specified, the (un)suppression will be applied to all rules. This is equivalent to specifying item *.
file
is specified, the (un)suppression will be applied only to the current file. line
is specified, the (un)suppression will be applied starting from the line that contains the directive.parasoft suppress file "*file with whitespace.cpp"
file
* pattern in a header file makes it valid for all the files that include that header file. When no file
is specified, suppression will be applied only to that header.parasoft-suppress
directive is quite distinct from the other parasoft on, parasoft off,
and parasoft suppress/unsuppress
directives. parasoft-suppress
suppresses only the current line (the line with the directive) and uses different syntax than the other directives.To view the suppressed messages that were reported in a subsequent test run:
The Suppression Messages view will display the following information:
To sort the Suppressions view contents by one of the column headings, click that column heading.
You can edit a suppression’s message or reason by right-clicking the suppression in the Suppressions view, choosing Edit Message or Edit Reason from the shortcut menu that opens, then modifying the message or reason in the dialog that opens. |
You can restrict which suppressions are shown in the Suppressions view by using the available suppressions filter.
To filter the suppressions shown in the Suppressions view:
To unsuppress a task:
If this same static analysis violation is found in subsequent tests of this project, the task will be reported in the Quality Tasks view.