C++ Logo

std-proposals

Advanced search

Re: Make abstract classes non-deletable if no virtual destructor available

From: Ville Voutilainen <ville.voutilainen_at_[hidden]>
Date: Tue, 24 Mar 2020 21:42:57 +0200
On Tue, 24 Mar 2020 at 21:24, Kilian Henneberger via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> While my initial proposal would require changing the C++ language, a (not equal but similar) approach would be
> to only change the implementation of std::default_delete to:
>
> template<class T>
> struct default_delete {
> void operator()(T* ptr) {
> static_assert(!is_abstract_v<T> || has_virtual_destructor_v<T>);
> delete ptr;
> }
> };
>
> As (hopefully) most people use a abstract base class together with unique_ptr,
> this would also make the language more safe.

I have a homework assignment for you:

1) what is the cost of the suggested language change? Is that cost
paid by users who don't use its benefits?
2) same question for the library change?
3) is there more than just one cost?
4) are the language and library costs different?

Received on 2020-03-24 14:45:59