Disable single warning error
#pragma warning( push )
#pragma warning( disable : 4101)
// Your function
#pragma warning( pop )
How can I disable a specific warning for a C# project in VS2012?
The warning you're getting has a number (e.g. CS2000), so what you need to do is right-click on the project, go to the Build
tab, and add that warning to the Suppress warnings
text box. You can subsequently suppress more than one by separating them with a comma (e.g. CS2000,CS2001).
Is it possible to disable specific compiler warnings?
To suppress specific warnings for Visual C# or F#:
- In Solution Explorer, choose the project in which you want to suppress warnings.
- On the menu bar, choose View, Property Pages.
- Choose the Build page.
- In the Suppress warnings box, specify the error codes of the warnings that you want to suppress, separated by semicolons, and then rebuild the solution.
Check out here for more info on how to suppress specific warning for Visual C++ and Visual Basic.
Another ways is to use #pragma warning
can enable or disable certain warnings.:
#pragma warning disable warning-list
#pragma warning restore warning-list
warning-list
A comma-separated list of warning numbers. Enter the numbers alone, without the "CS" prefix.
When no warning numbers are specified, disable disables all warnings and restore enables all warnings.
How to disable warnings in only one project?
- In Visual Studio open the project's Properties tab
- Go to the "Build" tab
- Set the "Warning Level" to 0
For details on the different warning levels see:
C# Compiler Options > /warn (Specify Warning Level)
How to disable specific warning inherited from parent in Visual Studio?
In your question, you're enabling warning 44101
(which doesn't exist if I'm right?), but disabling warning 4101
: 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 at l
for the warning number specified by nnnn
. So /w44101
enables warning number 4101
at level 4
.
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 warning 4101
at "global scope" at warning level 4:
add_compile_options(/w44101)
You can then use target_compile_definitions
to disable it per-target:
add_library(foo ...)
target_compile_definitions(foo PUBLIC /wd4101)
EDIT:
From your comments, in the head CMake file of the repo there is:
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /w44101")
And in your project CMake file you attempt to do:
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4101")
What you should do is removing the /w44101
from CMAKE_CXX_FLAGS
. You can achieve this using string(REPLACE ...)
to replace /w44101
with an empty string:
string(REPLACE "/w44101" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
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?")
How can I compile without warnings being treated as errors?
Thanks for all the helpful suggestions. I finally made sure that there were no warnings in my code, but again was getting this warning from SQLite 3:
Assuming signed overflow does not occur when assuming that (X - c) <= X is always true
which I fixed by adding the CFLAG -fno-strict-overflow.
Related Topics
Why Does Call-By-Value Example Not Modify Input Parameter
C++ Alignment When Printing Cout ≪≪
Nice Way to Append a Vector to Itself
How to Read and Manipulate CSV File Data in C++
Scope Vs. Lifetime of Variable
Understanding of Pthread_Cond_Wait() and Pthread_Cond_Signal()
Static_Assert Fails Compilation Even Though Template Function Is Called Nowhere
Opengl Scale Single Pixel Line
Createprocess from Memory Buffer
Global Variable Within Multiple Files
What Is the Worst Real-World Macros/Pre-Processor Abuse You'Ve Ever Come Across
How to Call a Function on All Variadic Template Args
Is the Size of Std::Array Defined by Standard
Conversion Constructor Vs. Conversion Operator: Precedence