/w, /W0, /W1, /W2, /W3, /W4, /w1, /w2, /w3, /w4, /Wall, /wd, /we, /wo, /Wv, /WX (Warning Level)
Specifies how the compiler generates warnings for a given compilation.
/w /W0 /W1 /W2 /W3 /W4 /Wall /Wv[:version] /WX /w1warning /w2warning /w3warning /w4warning /wdwarning /wewarning /wowarning
The warning options specify which compiler warnings to display and the warning behavior for the entire compilation.
The warning options and related arguments are described in the following table:
|/w||Suppresses all compiler warnings.|
|Specifies the level of warnings to be generated by the compiler. Valid warning levels range from 0 to 4:
/W0 suppresses all warnings. This is equivalent to /w.
/W1 displays level 1 (severe) warnings. /W1 is the default setting in the command line compiler.
/W2 displays level 1 and level 2 (significant) warnings.
/W3 displays level 1, level 2 and level 3 (production quality) warnings. /W3 is the default setting in the IDE.
/W4 displays level 1, level 2, and level 3 warnings, and all level 4 (informational) warnings that are not turned off by default. We recommend that you use this option to provide lint-like warnings. For a new project, it may be best to use /W4 in all compilations; this will ensure the fewest possible hard-to-find code defects.
|/Wall||Displays all warnings displayed by /W4 and all other warnings that /W4 does not include—for example, warnings that are off by default. For more information, see Compiler Warnings That Are Off By Default.|
|/Wv[:version]||Displays only warnings introduced in compiler version version and earlier. You can use this option to suppress new warnings in code when you migrate to a newer version of the compiler, and to maintain your existing build process while you fix them. The optional parameter version takes the form nn[.mm[.bbbbb]] where nn is the major version number, mm is the optional minor version number, and bbbbb is the optional build number of the compiler. For example, use /Wv:17 to display warnings introduced in Visual Studio 2012 (that is, any version of the compiler that has a major version number of 17) or earlier, but suppress warnings introduced in Visual Studio 2013 (major version 18) and later. By default, /Wv uses the current compiler version number, and no warnings are suppressed. For information about which warnings are suppressed by compiler version, see Compiler Warnings by compiler version.|
|/WX||Treats all compiler warnings as errors. For a new project, it may be best to use /WX in all compilations; resolving all warnings ensures the fewest possible hard-to-find code defects.
The linker also has a /WX option. For more information, see /WX (Treat Linker Warnings as Errors).
|Sets the warning level for the warning number specified by nnnn. This lets you change the compiler behavior for that warning when a specific warning level is set. You can use these options in combination with other warning options to enforce your own coding standards for warnings, rather than the default ones provided by Visual Studio.
For example, /w34326 causes C4326 to be generated as a level 3 warning instead of level 1. If you compile by using both the /w34326 option and the /W2 option, warning C4326 is not generated.
|/wdnnnn||Suppresses the compiler warning that is specified by nnnn.
For example, /wd4326 suppresses compiler warning C4326.
|/wennnn||Treats the compiler warning that is specified by nnnn as an error.
For example, /we4326 causes warning number C4326 to be treated as an error by the compiler.
|/wonnnn||Reports the compiler warning that is specified by nnnn only once.
For example, /wo4326 causes warning C4326 to be reported only once, the first time it is encountered by the compiler.
If you use any of the warning options when you create a precompiled header by using the /Yc option, any use of the precompiled header by using the /Yu option causes those same warning options to be in effect again. You can override the warning options set in the precompiled header by using another warning option on the command line.
You can use a #pragma warning directive to control the level of warning that is reported at compile time in specific source files.
Warning pragma directives in source code are unaffected by the /w option.
The build errors documentation describes the warnings and warning levels, and indicates why certain statements may not compile as you intend.
To set the compiler options in the Visual Studio development environment
Open the project's Property Pages dialog box. For details, see Set C++ compiler and build properties in Visual Studio.
To set the /W0, /W1, /W2, /W3, /W4, /Wallm /Wv, /WX or /WX- options, select the Configuration Properties > C/C++ > General property page.
To set the /W0, /W1, /W2, /W3, /W4, or /Wall options, modify the Warning Level property.
To set the /WX or /WX- options, modify the Treat Warnings as Errors property.
To set the version for the /Wv option, enter the compiler version number in the Warning Version property.
To set the /wd or /we options, select the Configuration Properties > C/C++ > Advanced property page.
To set the /wd option, select the Disable Specific Warnings property drop down control and then choose Edit. In the edit box in the Disable Specific Warnings dialog, enter the warning number. To enter more than one warning, separate the values by using a semicolon (;). For example, to disable both C4001 and C4010, enter 4001;4010. Choose OK to save your changes and return to the Property Pages dialog.
To set the /we option, Select the Treat Specific Warnings As Errors property drop down control and then choose Edit. In the edit box in the Treat Specific Warnings As Errors dialog, enter the warning number. To enter more than one warning, separate the values by using a semicolon (;). For example, to treat both C4001 and C4010 as errors, enter 4001;4010. Choose OK to save your changes and return to the Property Pages dialog.
To set the /wo option, select the Configuration Properties > C/C++ > Command Line property page. Enter the compiler option in the Additional Options box.
Choose OK to save your changes.
To set the compiler option programmatically
We'd love to hear your thoughts. Choose the type you'd like to provide:
Our feedback system is built on GitHub Issues. Read more on our blog.