Поделиться через


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

#pragma prefast(disable:1 11 221, "explanation for the disable")

Disables the warnings specified in a given warning list.

enable

#pragma prefast(enable:1 11 221, "explanation for the enable")

Enables the warnings specified in a particular warning.

push

#pragma prefast(push)

Pushes the current disabled/enabled state of all the Code Analysis tool warnings into a stack.

Similar to #pragma warning(push).

pop

#pragma prefast(pop)

Resets the disabled/enabled state of all the Code Analysis warnings to the state of the matching prefast(push) statement.

suppress

5 MyFunction(i,

#pragma prefast(suppress: 1, "PREfast noise: pftbug-401")

6 j);

Suppresses the warnings in the next line after the suppress statement.

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

See Also

Reference

Prefast Code Analysis Tool

Concepts

Device Compiler Security Improvement Options