[Bug c++/91859] Optnization -O2 removes valid and necessary code

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon Sep 23 11:05:00 GMT 2019


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91859

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Domingo Alvarez from comment #0)
> The sample code is similar to a production code that do some work inside the
> custom delete if the "next" pointer is not NULL.

That's not valid. THe operator delete gets called after the object's destructor
has run, which means you can't access its members.

You can either fix the code, or use -fno-lifetime-dse to tell GCC to disable
the valid optimizations that break your invalid code.


More information about the Gcc-bugs mailing list