Pragma Prefast to Suppress Warning Messages (Compact 7)
3/12/2014
You can use pragma prefast, to suppress specific warnings when you run prefast.
Syntax
#pragma prefast(
specifier {: warning number list separated by whitespace}
(, " comment field description")
Parameters
Specifier | Example | Description |
---|---|---|
disable |
|
Disables the warnings specified in a given warning list. |
enable |
|
Enables the warnings specified in a particular warning. |
push |
|
Pushes the current disabled/enabled state of all the Code Analysis tool warnings into a stack. Similar to |
pop |
|
Resets the disabled/enabled state of all the Code Analysis warnings to the state of the matching |
suppress |
|
Suppresses the warnings in the next line after the In this example, warning 1 on line 6 is suppressed. |
Remarks
Because pragma prefast is an extension to the PREfast AST compiler, it is not recognized by other compilers, including the C++ compiler included with Visual C++ 6.0. This results in a 4068 warning. This warning can cause builds to fail under -W4 -Wx flags.
To use pragma prefast, add the following to a header that is used in all your source files:
#ifndef _PREFAST_
#pragma warning(disable:4068)
#endif
Example
The following example suppresses a warning C6308 on the next statement. The comment field allows arbitrary strings, useful for describing why the message is suppressed.
#pragma prefast(suppress:C6308, "the pointer was saved above (PREfast bug 508)")