Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MSVC - stop warnings in headers

I'm using MSVC with a CMaked project. As a result, I've enabled many of the flags on MSVC which were enabled for gcc and clang. However, the /Wall warning level is giving me some pain; it warns me about all kinds of things in included headers, like stdio.h and boost headers. Is there a way to stop MSVC from warning me about things in headers? I like my warning levels, but I only want them enabled for me.

like image 798
bfops Avatar asked Nov 27 '10 15:11

bfops


People also ask

How do I turn off error warnings?

Description. We currently have only two ways to disable compiler warnings-as-errors: either make none of them errors using --disable-warnings-as-errors or disable all errors with a compiler flag. There is no way to disable specific warnings-as-errors from the SCons command line due to the order of the compiler flags.

How do you suppress warnings in VS code?

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.

How do I turn off warnings in GCC?

If the value of y is always 1, 2 or 3, then x is always initialized, but GCC doesn't know this. To suppress the warning, you need to provide a default case with assert(0) or similar code. This option also warns when a non-volatile automatic variable might be changed by a call to longjmp.


1 Answers

/Wall is very pedantic. /W4 is probably all you really need. To answer your question, you can disable specific warnings around your headers with:

 #pragma warning(disable:xxxx)
 #include <yourheader.h>
 #pragma warning(default:xxxx)

Or change the warning level with:

 #pragma warning(push,3)
 #include <yourheader.h>
 #pragma warning(pop)

See the MSDN documentation: http://msdn.microsoft.com/en-us/library/2c8f766e.aspx

like image 94
Mark Tolonen Avatar answered Oct 21 '22 22:10

Mark Tolonen