Is Using #Pragma Warning Push/Pop the Right Way to Temporarily Alter Warning Level

Is using #pragma warning push/pop the right way to temporarily alter warning level?

The first method is the best way to do it, IMO. I know of no problems with it.

Simply bear in mind that a #pragma is compiler specific so don't expect it to work on every compiler out there :)

How to fix issues with #pragma disabling warnings that aren't getting correctly popped

It looks like the only solution to this problem is to either fix the bug in the third party code or to manually add #pragma warning(pop) multiple times after including the third party files until the warnings start showing up. For me, I had to add that line four times.

Both of these options suck but so far there's no other way around it.

Is there a way to disable all warnings with a pragma?

You can push/pop a low level of warning, like this:

#pragma warning(push, 0)        

#include <boost/bind.hpp>
#include <boost/shared_ptr.hpp>
// ...

#pragma warning(pop)

But know that it's not possible to disable all warnings. For example, some linker warnings are impossible to turn off.

Can't disable compiler warning in VS2015

Thanks to @Drop's suggestion above, I checked what was shown in the Compiler Settings after I entered 4623 in the "Disable Specific Warnings" field. I was surprised to see /wd"4623". When I removed this then added /wd4623 in the "Additional Options" field the warning disappeared.

This seems like a bug in Visual Studio 2015 but I can't find any reference to it.

Update: The bug is still there in Visual Studio 2015 Update 3, so I've reported it to Microsoft and they can recreate it.

What is the best solution for suppressing warning from a MS include (C4201 in mmsystem.h)

Something like

#pragma warning(push, disable: 4201)
#include <mmsystem.h>
#pragma warning(pop)


Related Topics



Leave a reply



Submit