Suppose I am working on a large code base that has warning w44101
enabled by default. Meaning if I go into my project and right click properties -> C/C++ -> Command Line -> /w44101
shows up in the additional options section.
I want to be able to disable this warning by altering the configuration instead of the source code. I tried going into properties -> C/C++ -> All Options -> Disable Specific Warnings and put in 4101
, and this actually produces a /wd"4101"
in properties -> C/C++ -> Command Line. However, when I compile my project, it still throws the 4101
warning. Why doesn't /wd"4101"
and /w44101
cancel out each other?
I am on Windows 10 with Visual Studio 2015. What is the correct way to disable this warning? It will be preferable if the proposed solutions could be invoked with some type of function in CMake since the .sln
file of this code base is generated by CMake.
EDIT: This code base I am working on has a strict compile flag setup by default. It is compiled with /W4
and /WX
. Also additional level 4 warnings, to name a few as an example, /w44101
, /w44062
, /w44191
etc.
In your question, you're enabling warning
44101
(which doesn't exist if I'm right?), but disabling warning4101
: is that a typo?EDIT:
You answered this in the comments of your question. Reading MSDN documentation,
/wlnnnn
option allows to set the warning level atl
for the warning number specified bynnnn
. So/w44101
enables warning number4101
at level4
.Anyway, if your projects are generated with CMake,
add_compile_options
can be used to add options to the compilation of source files in the current directory. This can be used to enable the warning4101
at "global scope" at warning level 4:You can then use
target_compile_definitions
to disable it per-target:EDIT:
From your comments, in the head CMake file of the repo there is:
And in your project CMake file you attempt to do:
What you should do is removing the
/w44101
fromCMAKE_CXX_FLAGS
. You can achieve this usingstring(REPLACE ...)
to replace/w44101
with an empty string:Obviously, the best solution would be to fix the code generating the warning.
4101
is about unused variables, that's easy to fix ;)(see related question "How do I best silence a warning about unused variables?")