Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
To manage warning state, list all code analysis warnings in a separate header file. Include the header file in the source file. Use warning pragma to override the settings in the header file.
To enable or disable a code analysis warning
Create a header file that lists all the code analysis warnings and their initial state, as shown in the following code:
// WarningState.h #pragma warning ( default : 6001 ) #pragma warning ( disable : 6011 ) // more warnings here // end of file
Include WarningState.h in the application header file. In this case, MyApplication.h represents the header file.
// MyApplication.h file #include "WarningState.h" // ... // end of file
Include MyApplication.h file in the source code file. In this case, MyApplication.cpp represents the source file.
// MyApplication.cpp file #include "MyApplication.h"
To modify the warning state, use the pragma warning-specifier in a .cpp file, as shown in the following code:
// MyApplication.cpp file #include "MyApplication.h" #pragma warning ( disable: 6001 ) #pragma warning ( default : 6001 )
Disable All Code Analysis Warnings
Your project might include files, such as third-party source code, for which you do not want to see code analysis warnings. The following code example disables all code analysis warnings for the included third-party files.
To disable all code analysis warnings for included third-party files
Add the following code to your header file.
#include <codeanalysis\warnings.h> #pragma warning( push ) #pragma warning ( disable : ALL_CODE_ANALYSIS_WARNINGS ) #include <third-party include files here> #pragma warning( pop )