Condividi tramite


/w, /W0, /W1, /W2, /W3, /W4, /w1, /w2, /w3, /w4, /Wall, /wd, /we, /wo, /Wv, /WX (Warning Level)

 

The latest version of this topic can be found at -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.

Syntax

/w  
/W0  
/W1  
/W2  
/W3  
/W4  
/Wall  
/Wv:<version>  
/WX  
/w1<warning>   
/w2<warning>   
/w3<warning>   
/w4<warning>   
/wd<warning>   
/we<warning>   
/wo<warning>  

Remarks

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:

Option Description
/w Disables all compiler warnings.
/W0
 /W1
 /W2
 /W3
 /W4
Specifies the level of warnings to be generated by the compiler. Valid warning levels range from 0 to 4:
- /W0 disables all warnings.
- /W1 displays level 1 (severe) warnings. /W1 is the default setting.
- /W2 displays level 1 and level 2 (significant) warnings.
- /W3 displays level 1, level 2 and level 3 (production quality) warnings.
- /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 only to provide lint-like warnings. However, 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 Suppress new warnings that were not generated by the specified version of the compiler. If you have code that compiled without warnings when using an older version of the compiler, you can use this option to suppress new warnings in code during migration to a new compiler. We recommend you only use this option temporarily to satisfy clean build requirements, while you update your code to remove the new warnings. The version parameter 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. When the minor or build version numbers are omitted, new warnings are suppressed only in releases of the compiler that have a higher major version number, or if present, minor version number. For example, use /Wv:17 to disable warnings introduced after all versions of Visual C++ 2012 (compiler version 17.xx.xxxxx). By default, when /Wv is not specified, no warnings are suppressed.
/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).
/w1nnnn
/w2nnnn
/w3nnnn
/w4nnnn
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 Disables the compiler warning that is specified by nnnn.

For example, /wd4326 disables 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.

Pragma warning 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 option in the Visual Studio development environment

  1. Open the project's Property Pages dialog box. For details, see How to: Open Project Property Pages.

  2. Select C/C++.

  3. On the General property page, modify the Warning Level or Treat Warnings as Errors properties.

  4. On the Advanced property page, modify the Disable Specific Warnings property.

  5. For the remaining options, on the Command Line property page, type the compiler option in the Additional Options box.

To set the compiler option programmatically

See Also

Compiler Options
Setting Compiler Options