#pragma warning(disable: 4577) doesn't work in VS2017 - c++

I'm disabling the warning C4577 at the top of my C++ file, outsides of any scope:
#pragma warning(disable: 4577)
But I'm still getting a lots of warnings like:
warning C4577: 'noexcept' used with no exception handling mode specified; termination on exception is not guaranteed.
How can I disable the warning only for my file?
Regards,
Christian

Related

Unknown pragma ignored: warning [duplicate]

What's the closest GCC equivalent to this MSVC preprocessor code?
#pragma warning( push ) // Save the current warning state.
#pragma warning( disable : 4723 ) // C4723: potential divide by 0
// Code which would generate warning 4723.
#pragma warning( pop ) // Restore warnings to previous state.
We have code in commonly included headers which we do not want to generate a specific warning for. However, we want files which include those headers to continue to generate that warning (if the project has that warning enabled).
This is possible in GCC since version 4.6, or around June 2010 in the trunk.
Here's an example:
#pragma GCC diagnostic push
#pragma GCC diagnostic error "-Wuninitialized"
foo(a); /* error is given for this one */
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wuninitialized"
foo(b); /* no diagnostic for this one */
#pragma GCC diagnostic pop
foo(c); /* error is given for this one */
#pragma GCC diagnostic pop
foo(d); /* depends on command line options */
The closest thing is the GCC diagnostic pragma, #pragma GCC diagnostic [warning|error|ignored] "-Wwhatever". It isn't very close to what you want, and see the link for details and caveats.
I've done something similar. For third-party code, I didn't want to see any warnings at all. So, rather than specify -I/path/to/libfoo/include, I used -isystem /path/to/libfoo/include. This makes the compiler treat those header files as "system headers" for the purpose of warnings, and so long as you don't enable -Wsystem-headers, you're mostly safe. I've still seen a few warnings leak out of there, but it cuts down on most of the junk.
Note that this only helps you if you can isolate the offending code by include-directory. If it's just a subset of your own project, or intermixed with other code, you're out of luck.
This is an expansion to Matt Joiner's answer.
If you don't want to spawn pragmas all over your code, you can use the _Pragma operator:
#ifdef __GNUC__
# define DIAGNOSTIC_ERROR(w) _Pragma("GCC diagnostic error \"" w "\"")
# define DIAGNOSTIC_IGNORE(w) _Pragma("GCC diagnostic ignore \"" w "\"")
# define DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push")
# define DIAGNOSTIC_POP _Pragma("GCC diagnostic pop")
#endif
// (...)
DIAGNOSTIC_ERROR("-Wuninitialized")
foo(a); // Error
DIAGNOSTIC_PUSH
DIAGNOSTIC_IGNORE("-Wuninitialized")
foo(a); // No error
DIAGNOSTIC_POP
foo(a); // Error

Boost "destructor is not virtual" error in MSVC 11

I am trying to compile a program with boost 1.57.0 using MSVC 11.0 and I get the following error:
z:\d\dev\boost_1_57_0\boost\exception\exception.hpp(171) : error C4265: 'boost::exception_detail::error_info_container' but destructor is not virtual instances of this class may not be destructed correctly
Is there anything I can do about it?
These posts didn't seem to offer a solution
http://boost.2283326.n4.nabble.com/boost-exception-detail-error-info-base-does-not-have-virtual-destructor-td3384903.html
http://boost.2283326.n4.nabble.com/Re-exception-warning-about-non-virtual-destructor-resolution-td4554753.html
I should've thought about this before. The error is a warning promoted to an error through /W4. I managed to fix it by wrapping a warning disable around the include.
#pragma warning(push)
#pragma warning(disable : 4265)
#include <boost/...>
#pragma warning(pop)

how to disable the warning (seems not one common warning )for this code sample in c++/gcc compile?

how to disable the warning for this code sample in c++/gcc compile?
the warning seems it isn't a common warning. So how to disable it?
is it similar with followed code?
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-variable" //I don't know ignore what for the code in pic.
#include "subfolder/ClassTwo.h"
#pragma GCC diagnostic pop
but ignore what?
I tried one answer but pop one error:
for
#pragma GCC diagnostic push
it pop:
warning: expected [error|warning|ignored] after â#pragma GCC diagnosticâ
It is strange to see this warning popping up in Boost. The compiler flag to disable this warning is -Wno-reorder, as per gcc's man page.
In your case, you can use:
#pragma GCC diagnostic ignored "-Wreorder"

Can I exclude some specific warnings from "treat warnings as errors" without disabling them?

In my Visual C++ code I want to have /WX - "treat warnings as errors". This makes me deal with each warning, including C4996 - "X was declared deprecated" which I don't want to address - I don't want to change code at the moment and I don't want to disable C4996 so that it remains in the output. So ideally I'd like to have something like:
#pragma warning( ExcludeFromWX:4996)
so that all warnings except this one are treated as errors when /WX is used and this warning is just displayed and compilation continues.
Is it possible to get such behavior?
You might be able to reset the specified warning by using following pragma. I did not test it though and you did not mention trying this:
UPDATE
Changing the warning level should succeed
#pragma warning( 4 : 4996 )
This does not work:
#pragma warning( default : 4996 )

Selectively disable GCC warnings for only part of a translation unit

What's the closest GCC equivalent to this MSVC preprocessor code?
#pragma warning( push ) // Save the current warning state.
#pragma warning( disable : 4723 ) // C4723: potential divide by 0
// Code which would generate warning 4723.
#pragma warning( pop ) // Restore warnings to previous state.
We have code in commonly included headers which we do not want to generate a specific warning for. However, we want files which include those headers to continue to generate that warning (if the project has that warning enabled).
This is possible in GCC since version 4.6, or around June 2010 in the trunk.
Here's an example:
#pragma GCC diagnostic push
#pragma GCC diagnostic error "-Wuninitialized"
foo(a); /* error is given for this one */
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wuninitialized"
foo(b); /* no diagnostic for this one */
#pragma GCC diagnostic pop
foo(c); /* error is given for this one */
#pragma GCC diagnostic pop
foo(d); /* depends on command line options */
The closest thing is the GCC diagnostic pragma, #pragma GCC diagnostic [warning|error|ignored] "-Wwhatever". It isn't very close to what you want, and see the link for details and caveats.
I've done something similar. For third-party code, I didn't want to see any warnings at all. So, rather than specify -I/path/to/libfoo/include, I used -isystem /path/to/libfoo/include. This makes the compiler treat those header files as "system headers" for the purpose of warnings, and so long as you don't enable -Wsystem-headers, you're mostly safe. I've still seen a few warnings leak out of there, but it cuts down on most of the junk.
Note that this only helps you if you can isolate the offending code by include-directory. If it's just a subset of your own project, or intermixed with other code, you're out of luck.
This is an expansion to Matt Joiner's answer.
If you don't want to spawn pragmas all over your code, you can use the _Pragma operator:
#ifdef __GNUC__
# define DIAGNOSTIC_ERROR(w) _Pragma("GCC diagnostic error \"" w "\"")
# define DIAGNOSTIC_IGNORE(w) _Pragma("GCC diagnostic ignore \"" w "\"")
# define DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push")
# define DIAGNOSTIC_POP _Pragma("GCC diagnostic pop")
#endif
// (...)
DIAGNOSTIC_ERROR("-Wuninitialized")
foo(a); // Error
DIAGNOSTIC_PUSH
DIAGNOSTIC_IGNORE("-Wuninitialized")
foo(a); // No error
DIAGNOSTIC_POP
foo(a); // Error