On Wed, 22 Sept 2021 at 18:56, Antony Polukhin <antosh...@gmail.com> wrote:
>
> ср, 22 сент. 2021 г. в 20:44, Jonathan Wakely <jwakely....@gmail.com>:
> >
> > On Wed, 22 Sept 2021 at 18:09, Antony Polukhin wrote:
> > >
> > > std::unique_ptr allows construction from std::unique_ptr of derived
> > > type as per [unique.ptr.single.asgn] and [unique.ptr.single.ctor]. If
> > > std::default_delete is used with std::unique_ptr, then after such
> > > construction a delete is called on a pointer to base. According to
> > > [expr.delete] calling a delete on a non similar object without a
> > > virtual destructor is an undefined behavior.
> > >
> > > This patch turns that undefined behavior into static assertions inside
> > > std::unique_ptr.
> >
> > The undefined behaviour only happens if the destructor is actually
> > reached at runtime, but won't these static assertions make it
> > ill-formed to instantiate these members, even if the UB never happens?
> >
> > For example, if you ensure that release() is called before
> > destruction, the undefined delete never happens.
>
> Ugh... I've missed that use case. Patch is just wrong, discard it

It's a horrible (and probably unrealistic) use case, but we're
required to accept it.

I should a test case to the testsuite, just to make sure we continue
to accept it without errors.

Reply via email to