/w, /W0, /W1, /W2, /W3, /W4, /w1, /w2, /w3, /w4, /Wall, /wd, /we, /wo, /Wv, /WX (Warning Level)
TOC
Collapse the table of content
Expand the table of content

/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
/w1<warning> 
/w2<warning> 
/w3<warning> 
/w4<warning> 
/wd<warning> 
/we<warning> 
/wo<warning>

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.

/Wvversion

Disable warnings introduced in compiler versions newer than version. You can use this option to determine if there are new warnings in code that compiled without warnings when using an older version of the compiler, and to remove them from your build. 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 /Wv17.00.00000 to disable warnings introduced in Visual C++ 2012 and later. By default, /Wv uses the current compiler version number, and no warnings are disabled.

/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).

/w1n

/w2n

/w3n

/w4n

Sets the warning level for the warning number specified by n. 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.

/wdn

Disables the compiler warning that is specified by n.

For example, /wd4326 disables compiler warning C4326.

/wen

Treats the compiler warning that is specified by n as an error.

For example, /we4326 causes warning number C4326 to be treated as an error by the compiler.

/won

Reports the compiler warning that is specified by n 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

Show:
© 2016 Microsoft