Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable a single warning in Visual Studio

Is there a compiler switch to enable a single warning in Visual Studio?

The reason I ask is I want to enable warning C4265 which is off by default. My searching has only turned up ways to turn warnings off.

Even Microsoft pages called How to: Enable or Disable Compiler Warnings still only mention disabling.

like image 217
0xC0DEFACE Avatar asked Nov 11 '10 06:11

0xC0DEFACE


People also ask

How do I enable or disable compiler warnings in Visual Studio?

Turn off the warning for a project in Visual StudioSelect the Configuration Properties > C/C++ > Advanced property page. Edit the Disable Specific Warnings property to add 4996 . Choose OK to apply your changes.

How do I change the warning level in Visual Studio?

In the left pane of the Property Pages, click to expand Configuration Properties. 3. Under Configuration Properties, click to select C/C++. Level4 (/W4).

How do I suppress an error in Visual Studio?

Suppress specific warnings for Visual C# or F# Or, select the project node and press Alt+Enter. Choose Build, and go to the Errors and warnings subsection. In the Suppress warnings or Suppress specific warnings box, specify the error codes of the warnings that you want to suppress, separated by semicolons.


2 Answers

If you want to turn it on (or off) in the project setting, you have to go to:

Configuration Properties -> C/C++ -> Command Line and then under Additional Options you can enter:

/w3#### to set your warning to level 3, and thus enable it; or you can enter /wd#### to disable a warning.


Current (2015,2017,2019,...) Visual Studio Versions also have a dedicated setting to disable warnings under:

Configuration Properties -> C/C++ -> Advanced : Disable Specific Warnings ... is equivalent to /wd####.

Also useful in recent versions: C/C++ -> All Options and then filter for e.g. "warn".

It would appear that enabling á la /w3#### is not yet exposed explicitly.

like image 138
Martin Ba Avatar answered Sep 28 '22 21:09

Martin Ba


#pragma warning(default:4265) 

It might seem like that would set the warning to it's default setting(which would be disabled), but that's not the case. It turns it on.

http://msdn.microsoft.com/en-us/library/2c8f766e%28VS.80%29.aspx

You can also do this:

#pragma warning(X:4265) // where X is the warning level(1,2,3 or 4) that you want this warning to be generated at 
like image 33
Benjamin Lindley Avatar answered Sep 28 '22 23:09

Benjamin Lindley