Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exception.hpp: warning C4265 given by Visual Studio #23

Closed
bersbersbers opened this issue May 10, 2019 · 5 comments
Closed

exception.hpp: warning C4265 given by Visual Studio #23

bersbersbers opened this issue May 10, 2019 · 5 comments

Comments

@bersbersbers
Copy link

This has been reported before (https://svn.boost.org/trac10/ticket/13227), but I am not sure that tracker is still active. The problem is still relevant with boost 1.65.1 and 1.70.

Quoting:

MSVC falsely report a missing virtual destructor inside exception.hpp Would it be possible to add a "pragma warning (disable:4265)" in this file ? This will not happen with the default settings of Visual Studio : it happens when trying to raise the warning level (/we4265 : treat "misssing virtual destructor" as an error)

The above link has reproduction steps, in particular, https://github.com/ivsgroup/boost_warnings_minimal_demo

@mclow mclow transferred this issue from boostorg/boost May 18, 2019
@zajo
Copy link
Collaborator

zajo commented Oct 15, 2019

Sorry I had missed this. See boostorg/throw_exception@43a57d5

@Shawn1874
Copy link

I know this is closed, but the warning / error doesn't appear to be a false report. Instead of disabling the warning, shouldn't the destructor have been made virtual?

@zajo
Copy link
Collaborator

zajo commented Feb 2, 2022

It is incorrect for this destructor to be virtual. The destructor is never called via a pointer to the base type.

@Shawn1874
Copy link

As a general rule classes with virtual methods ought to have a virtual destructor which is the reason for the warning. It certainly wouldn't hurt anything for the the destructor to be virtual. There is nothing incorrect about a virtual, protected method. It seems like it was more of a preference for someone to disable the warning.

@zajo
Copy link
Collaborator

zajo commented Feb 2, 2022

It is a deliberate design decision. Marking a function virtual indicates dynamic polymorphism. In this design, calling the destructor polymorphically would be a logic error. In C++, this is communicated by declaring the destructor protected and non-virtual.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants