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

vekumar at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |vekumar at gcc dot gnu.org

--- Comment #8 from vekumar at gcc dot gnu.org ---
(In reply to Andrew Pinski from comment #4)
> (In reply to Andrew Pinski from comment #3)
> >             std::memset(ptr, 0, sizeof(bool));
> >             new (ptr) bool;
> > 
> > 
> > The memset here is dead. the lifetime of bool starts after the new.
> > 
> > GCC 16 is correct here.
> > 
> > gem5 needs to be fixed.
> 
> Swapping around the memset and the new is a fix. But the C++ standard is
> clear here that the lifetime of of type bool starts after the new operator
> and any store before it is not considered.

--snip--
Change in 6.8.4 [basic.life] paragraph 1 as follows:
The lifetime of an object o of type T ends when:
•       if T is a non-class type, the object is destroyed, or
•       if T is a class type, the destructor call starts, or
•       the storage which the object occupies is released, or is reused by an
object that is not nested within o (6.8.2 [intro.object]).
--Snip--

references: 
https://cplusplus.github.io/CWG/issues/2721.html
https://eel.is/c++draft/basic.life#1

--snip--
            std::memset(ptr, 0, sizeof(T));
            new (ptr) T;
-snip--

My understanding from the above same as Andrew. The lifetime of "ptr" used in
memset has ended when it is used in following placement new. Compiler can treat
the "memset" as dead store.

Reply via email to