Upraviť

Zdieľať cez


/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
/w1warning
/w2warning
/w3warning
/w4warning
/wdwarning
/wewarning
/wowarning

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 tables:

Option Description
/w Suppresses 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 suppresses all warnings. It's 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 aren't 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 option helps ensure the fewest possible hard-to-find code defects.
/Wall Displays all warnings displayed by /W4 and all other warnings that /W4 doesn't 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 the version compiler version and earlier. You can use this option to suppress new warnings in code when you migrate to a newer version of the compiler. It lets you 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 only warnings introduced in Visual Studio 2012 (major version 17) or earlier. That is, it displays warnings from any version of the compiler that has a major version number of 17 or less. It suppresses 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).

The following options are mutually exclusive with each other. The last option that's specified from this group is the one applied:

Option Description
/w1nnnn

/w2nnnn

/w3nnnn

/w4nnnn
Sets the warning level for the warning number specified by nnnn. These options let 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 isn't 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's encountered by the compiler.

If you use any warning options when you create a precompiled header, it keeps those settings. Using the precompiled header puts those same warning options in effect again. To override the precompiled header warning options, set another warning option on the command line.

You can use a #pragma warning directive to control the level of warning that's 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

  1. Open the project's Property Pages dialog box. For details, see Set C++ compiler and build properties in Visual Studio.

  2. To set the /W0, /W1, /W2, /W3, /W4, /Wall, /Wv, /WX, or /WX- options, select Configuration Properties > C/C++ > General.

    • 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.

  3. 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 dropdown 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 dropdown 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.

  4. To set the /wo option, select the Configuration Properties > C/C++ > Command Line property page. Enter the compiler option in the Additional Options box.

  5. Choose OK to save your changes.

To set the compiler option programmatically

See also

MSVC compiler options
MSVC compiler command-line syntax