Boost "destructor is not virtual" error in MSVC 11 - c++

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)

Related

Pragma ignoring comment [-Werror=unknown-pragmas]

I'm trying to make function which will return version from FileVersionInfo,
so far i built funtcion, but i have issue when i want to include version.lib
#pragma comment(lib, "version.lib")
I have tried to link, libversion.a, something like this
#pragma comment(lib, "libversion.a")
but, again compiler was returning error like first time
Pragma ignoring comment [-Werror=unknown-pragmas]
I have tried, many combinations from internet, i cant even remember all of them. I'm using MinGW compiler.
Thanks for your time i appricitate it :)
"This pragma to link libraries from C++ source code is only supported by MSVC"
Switched compiler from gcc/g++ to MSVC, that's only solution :(

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

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

Avoid weak-vtable warnings for classes only defined in a source file

I understand that a class class needs at least one virtual function defined in a source file (out of line), otherwise the vtable will need to be inserted into every object file.
I have the following situation:
//foo.cpp
struct Foo {
virtual int Bar() { return 1; }
virtual ~Foo() = default;
};
The clang code model in Qt Creator (4.5.2) emits a -Wweak-table warning for Foo.
Strictly speaking the warning is correct, as the vtable will be included in every translation unit. Practically, it's worthless because either way the vtable is only emitted in foo.o anyway.
How can I disable -Wweak-vtables only for classes defined in a source file?
It turns out that standalone clang does the right thing by default, only the clang code model in Qt creator shows the useless warning. It's already reported as QTCREATORBUG-19741, so there's nothing more to do than wait for an updated Qt creator version.
Not really sure, but where I work, we have some practices for disabling warnings in localized sources.
Under windows:
#pragma warning(push)
#pragma warning(disable : 4820)
//Rest of your includes (cstdio, vector...)
#pragma warning(pop) //For /Wall
Under gcc like:
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
//Rest of your includes (cstdio, vector...)
#pragma GCC diagnostic pop

MSVC std::_Pad no virtual destructor

I'm using
Microsoft (R) C/C++ Optimizing Compiler Version 17.00.50727.1 for x64
and when I do
#include <mutex>
#include <condition_variable>
I get
c:\program files (x86)\microsoft visual studio 11.0\vc\include\thr\xthread(172) : error C4265: 'std::_Pad' : class has virtual functions, but destructor is not virtual
instances of this class may not be destructed correctly
do I need to upgrade to a newer version of MSVC?
You don't need to update.
It is a warning that could be important when using virtual functions. If you allocate memory in a derived class you need a virtual destructor and freeing the memory on object destruction. Using std::mutex you are safe (huge disclaimer here).
You get rid of this warning by using #pragma warning. If you treat warnings as errors you have to get rid of it but never lower the compiler warnings level:
#pragma warning(push)
#pragma warning(disable:4265)
#include <mutex>
#pragma warning(pop)
Surround the warning with care, you don't want to disable warnings for the whole file, you might miss some essential warning.

Intentional compiler warnings for Visual C++ that appear in Error List?

How can you create a compiler warning (in the model of #error, except as a warning) on purpose in Visual C++ that will show up on the Error List with the correct file and line number?
GCC and other compilers offer #warning, but the MSVC compiler does not.
The "solution" at http://support.microsoft.com/kb/155196 does not parse in the Visual Studio error list.
Just add this to your common include file (ex, stdafx.h):
#define __STR2__(x) #x
#define __STR1__(x) __STR2__(x)
#define __LOC__ __FILE__ "("__STR1__(__LINE__)") : warning W0000: #pragma VSWARNING: "
#define VSWARNING(x) message(__LOC__ x)
Use this like:
#pragma VSWARNING("Is this correct?!?!")
The compiler will output:
c:\dir\file.h(11) : warning W0000: #pragma VSWARNING: Is this correct?!?!
And the Error List tab will show the warning nicely in the table:
Type Num Description File Line
[Warning] 13 warning W0000: #pragma VSWARNING: Is this correct?!?! file.h 11
exactly like a normal Visual Studio compiler warning.
This is kind of a silly answer to your question, but often, if I need to add an intentional warning, I will type something like:
#pragma asdfkljasdlfjasklfjklasjdfklj
which issues a Unknown Pragma warning with line number and all.