Subject: Re: [std-proposals] Make abstract classes non-deletable if no virtual destructor available
From: Henry Miller (hank_at_[hidden])
Date: 2020-03-23 17:24:06
I would word this as if there are any pure virtual functions the automatically generated destructor is protected. It gives the result you want by default, anyone who wants the virtual destructor already has to declare it. And if there really is a reason to have a non virtual public destructor it should be verbose enough to call attention to that unusual situation.
-- Henry Miller hank_at_[hidden] On Mon, Mar 23, 2020, at 15:19, Kilian Henneberger via Std-Proposals wrote: > Hello, > > an abstract class (a class that either defines or inherits at least one > function for which the final overrider is pure virtual) > cannot be instantiated. However it can be destroyed. But deleting a > Derived-object through a pointer to Base-object > leads to undefined behaviour if the destructor of the Base-class is not > virtual. > There also exists a CppCoreGuideline addressing this topic: > http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rc-dtor-virtual > > I want to propose that we make the attempt to delete a pointer to an > abstract class ill-formed, > if the abstract class does not have a (public) virtual destructor. > > This would turn what currently is UB into a compiler error. > But it also might imply that code which compiles today (even if leading > to UB), wont compile any longer after this change. > > I am looking forward to any feedback. > Best regards, > Kilian Henneberger > > > > -- > Std-Proposals mailing list > Std-Proposals_at_[hidden] > https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals >
STD-PROPOSALS list run by email@example.com
Standard Proposals Archives on Google Groups