Command line warning D9035: option 'Gm' has been deprecated and will be removed in a future release - visual-studio-2017

I am getting the warning message "cl : Command line warning D9035: option 'Gm' has been deprecated and will be removed in a future release" while building my project with Visual Studio 2017 latest update 15.9.2. How to resolve this warning?

Try selecting <inherit from parent or project defaults> for the Enable Minimal Rebuild option (under C/C++ > Code Generation). After this, the option should show No (/Gm-), not in bold. Make sure you do this for your project(s) (you could have several projects in the solution), and all property pages they inherit from.
I had the same problem using Visual Studio 2019, in the end the problem was in a second project I had in the same solution, that had the option set to Yes (/Gm).

According to the documentation
You may safely remove this option from your projects.

Project > Properties > Configuration Properties > C\C++ > Code Generation >
set the Enable Minimal Rebuild to no, and there is no warning.

Happened for me too. Did not manage to fix it through UI.
In the end I searched for "MinimalRebuild" in all project files and removed it manually - that helped

Properties > C\C++ > Code Generation > Enable Minimal Rebuild: DELETE value - and there is no warning.

UI did not work for me either. In the .vcxproj file search: "MinimalRebuild" I had missed a second one under Debug|Win32

just add this above your deprecated function
#pragma warning (disable : 4996);
example
#pragma warning (disable : 4996);
your_deprecated_function();

Related

/Zc:threadSafeInit flag in VS 2015

VS 2015 has a new flag /Zc:threadSafeInit that directs the compiler to generate code to make function local statics thread safe. However, I am unable to get this directive to take effect in my IDE. If I set it as Additional Options in the compiler command line property sheet, I get the following warning during build:
1>cl : Command line warning D9025: overriding '/Zc:threadSafeInit' with '/Zc:threadSafeInit-'
I don't see any instance of the latter anywhere in my project property sheets or .vcxproj files.
Anybody can guess what is going on here? Is there a possibility /Zc:threadSafeInit is conflicting with some other compiler option?

How to repair Visual Studio locals/watches in C++ (Debug build)

Sometimes VS autos/locals/watches break and instead of variables/values all I have is different kinds of:
CXX0029: Error: not struct pointer
CXX0033: Error: error in OMF type information
CXX0072: Error: type information missing or unknown
CXX0025: Error: operator needs class/struct/union
Rebuilding project, cleaning PDB/NCB etc doesn't solve it. What can I do?
Look at this Microsoft support note on: FIX: CXX0033 Error in OMF Type from Forward Class Declaration
Once you fix the PCH problem cited in the support note, I think all your errors will go away.
There is in fact a solution that lets you keep using precompiled headers: check out this more recent KB article and the documentation of the /Yl switch - which seems specifically tailored to this error.
Just add to the stdafx.cpp (or your own custom /Yc file) command line '/Ylxxxx', where xxxx stands for an arbitrary function name in your lib.
I recently faced symptoms identical to yours (in VS2010), and that solved it for me.
Are you trying to debug the "release" build? If so, many local variables will not exist as "debuggable" elements. You can get around this (if you must debug the release build) by debugging at the assembly level and look at the register values (vs. stack values, where auto/local would be in the debug build) and cast them appropriately in the "watch window".
Otherwise, build the Debug build and debug that build version. You'll get assertions where preconditions are not met, relevant/irrelevant stuff dumped to your output window, and more straight-forward debug single stepping.
It helped me to switch from using a program database (/ZI) to "c7 compatible" (/Z7). Switching off precompiled headers did not make a difference. Neither did rebuilding.

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.
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.
#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
Use:
#pragma warning(default:4265)
and compile with at least /W3.
Here's an explicit example from Microsoft:
http://msdn.microsoft.com/en-us/library/wzxffy8c(v=VS.90).aspx
To make the comment of Matthäus Brandl regarding #pragma warning more visible:
If you're compiling with a warning level lower than 3, you have to use this syntax:
#pragma warning (<warning level>: 4265)
Only if you compile with level 3 or higher you can do
#pragma warning (default: 4265)
because for warning 4265, default means level 3 (see MSDN).
The documentation for #pragma warning reads:
warning-specifier Meaning
1, 2, 3, 4 Apply the given level to the specified warning(s). This also turns on a specified warning that is off by default.
default Reset warning behavior to its default value. This also turns on a specified warning that is off by default. The warning will be generated at its default, documented, level.

VS 2008 Compiler option for flagging uninitialized variables

Is there a compiler option in VS 2008 (C++) to expose uninitialized variables? I'm trying to debug a problem where the "release" build of a DLL does not work but the "debug" build of the DLL does work.
iirc, setting warning level to 4 will help with this
cl.exe sample.cpp /analyze
here's the link on MSDN
You're looking for warning number C6001
My normal debug builds seem to have this warning enabled:
warning C4700: uninitialized local variable 'xxx' used
and the warning is not present in a release build.
I don't know if this is still relevant but I was just looking for the same thing and found a solution.
You can manually change the warning-level for single warnings. In your case you have to set the level for this particular warning at least as low as your configured level of default-warnings (usually 1 or 2).
Within the project-settings within the C/C++ settings enter a manual command-line switch:
/wYxxxx
with Y being the warninglevel (e.g. 1)
and xxxx being the warningnumber in this case you should enter
/w14701
Cheers

How can I inhibit warning 4200 in Visual Studio 2005?

I can inhibit many warnings in Visual Studio 2005 SP1 in the C/C++ Advanced property page, which causes the IDE to use the /wd switch on the command line which invokes the compiler. However, when I try to inhibit warning 4200 (nonstandard extension used : zero-sized array in struct/union), it still appears when I compile. (Of course it's justified; I'm just not in a position to fix the code, nor would it be worth bothering, because it's generated, and the warning is entirely benign under the circumstances.) Does anybody happen to know if this is a bug in the compiler? Or might there be something I can do about it?
To completely disable the warning in the file you can add the following to the top of the file
#pragma warning(disable:2400)
If you want some more flexibility other than a blanket disable for the file, the following page lists several other more fine grained options.
http://msdn.microsoft.com/en-us/library/2c8f766e(VS.80).aspx
It's unclear based on your information as to whether or not it's a bug in the compiler or a configuration issue. I would lean towards a configuration issue, specifically conflicting compiler options that is making it difficult to suppress the warning.
EDIT
OP mentioned they can't control the generated code so they can't directly include the pragma. If that's the case then try this trick. Say the file name is Generated.cpp. No longer include Generated.cpp as one of the files to compile. Instead create a new file called Example.cpp with the following contents
#pragma warning(disable:2400)
#include "Generated.cpp"
Now you'll get the text of Generated.cpp with the disabled warning by only compiling Example.cpp.
You mean like with pragma?
#pragma warning( disable : 2400 )