How to disable a specific warning inherited from a parent in Visual Studio?

Suppose I am working on a large code base which, by default, warns w44101 . Meaning, if I go to my project and right-click → C / C ++ → Command Prompt → /w44101 will appear in the advanced options section.

I want to disable this warning by changing the configuration instead of the source code. I tried going to properties -> C / C ++ -> All Options -> Disable Specific Warnings and putting in 4101 , and this actually creates the /wd"4101" properties in properties -> C / C ++ -> Command Line. However, when I compile my project, it still issues warning 4101 . Why /wd"4101" and /w44101 do not cancel each other?

I am on Windows 10 with Visual Studio 2015. What is the correct way to disable this warning? It would be preferable if the proposed solutions can be called using some function in CMake, since the .sln file of this code base is generated by CMake.

EDIT: This code base I'm working on has a strict compilation flag setting by default. It is compiled with /W4 and /WX . Also additional level 4 warnings, to name a few examples, /w44101 , /w44062 , /w44191 , etc.

+5
source share
1 answer

In your question, you include warning 44101 (which doesn't exist if I'm right?), But shutdown warning 4101 : is this a typo?

EDIT:

You answered this in the comments on your question. Reading MSDN documentation , the /wlnnnn option allows /wlnnnn to set the warning level to l for the warning number specified by nnnn . Thus, /w44101 resolves warning number 4101 at level 4 .


In any case, if your projects are generated using CMake, add_compile_options can be used to add parameters to the compilation of source files in the Current directory. This can be used to enable warning 4101 in the "global scope":

 add_compile_options(/w4101) 

Then you can use target_compile_definitions to disable it for each purpose:

 add_library(foo ...) target_compile_definitions(foo PUBLIC /wd4101) 

EDIT:

From your comments in the main CMake repo file there is:

 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /w44101") 

And in your project, the CMake file you are trying to make is:

 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4101") 

What you need to do is remove /w44101 from CMAKE_CXX_FLAGS . You can achieve this using string(REPLACE ...) to replace /w44101 an empty string:

 string(REPLACE "/w44101" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") 

Obviously, the best solution would be to fix the warning code. 4101 about unused variables that are easy to fix;)

(see the corresponding question. What is the best way to disable the warning about unused variables? )

+7
source

Source: https://habr.com/ru/post/1261443/


All Articles