[RFC] libstdc++: optional: Set _M_engaged after the call to destructor [PR127005]

Ville Voutilainen ville.voutilainen@gmail.com
Sun Aug 23 19:47:52 GMT 2026


On Sun, 23 Aug 2026 at 22:40, Ville Voutilainen
<ville.voutilainen@gmail.com> wrote:
>
> On Sun, 23 Aug 2026 at 22:38, Ville Voutilainen
> <ville.voutilainen@gmail.com> wrote:
> >
> > On Sun, 23 Aug 2026 at 22:26, Andrea Pinski
> > <andrew.pinski@oss.qualcomm.com> wrote:
> > >
> > > Sometimes the destructor will cause the optimizers not to see that
> > > _M_engaged has been to set to false (e.g. an external call). This
> > > means that we might get an uninitialized warning after the destructor
> > > in some cases.
> >
> > Can you elaborate on what kind of an uninitialized warning that is,
> > and what code triggers it?
>
> Never mind, I read the PR, that explains it.

..so yeah, we set _M_engaged to false before calling the destructor to
make sure it's false even if the destructor does horrific things, like
throws.
Which we don't have to do. If a destructor of an element given to a
stdlib facility throws, the user gets to keep both parts.

I think the patch makes sense. I have no objections to it as written.
I don't think I have objections to removing the pre-dtor clearing of
_M_engaged either.


More information about the Libstdc++ mailing list