MSVC++ should not emit the optional warning C4265 (virtual functions, non-virtual destructor) for a class marked as sealed - by Jeff Walden

Status : 

  Deferred<br /><br />
		The product team has reviewed this issue and has deferred it for consideration at a later time.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.


3
0
Sign in
to vote
ID 707497 Comments
Status Closed Workarounds
Type Bug Repros 2
Opened 11/22/2011 12:35:58 PM
Access Restriction Public

Description

The optional warning C4265 is this: "'class' : class has virtual functions, but destructor is not virtual".  It's supposed to warn that an instance of a derived class, if destroyed through a pointer to the base class with the non-virtual destructor, won't be destroyed correctly.

http://msdn.microsoft.com/en-us/library/wzxffy8c%28v=vs.80%29.aspx

This rationale is quite sensible.  However, if the class in question is a sealed class (that is, in the example at the URL above, instead of "class B" we had "class B sealed"), it can never be a base class.  Therefore, there can be no instances of derived classes which wouldn't be destroyed properly through a pointer to the base class.

Shouldn't the warning, then, be disabled when the class with a virtual function but a non-virtual destructor is also marked as sealed?
Sign in to post a comment.
Posted by gregorycu on 11/24/2014 at 11:03 PM
This remains a problem in Visual Studio 2013 Update 4.

A minimal amount of code to repo is below:

#pragma warning(default : 4265)

struct Base {
virtual void Foo() = 0;
};

struct Derived sealed : public Base {
void Foo() {}
~Derived() {}
};

int main() {}
Posted by Microsoft on 12/12/2011 at 5:18 PM
This has been fixed: if I compile the code with the latest compiler then I don't get any warning message.

Thanks
Jonathan Caves
Visual C++ Compiler Team
Posted by MS-Moderator07 [Feedback Moderator] on 11/22/2011 at 9:49 PM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.
Posted by MS-Moderator01 on 11/22/2011 at 12:44 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)