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

--- Comment #52 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Christopher Nerz from comment #45)
> This is a critical bug which renders gcc unusable for safety relevant
> systems using expected/variant or simple ipc.

I don't think your example demonstrates that.

>     alignas(8) std::byte buffer[8]; // some buffer
>     new (buffer) double{1}; // some completely trivial data
>     // reuse memory -> double ends lifetime, uint64 starts lifetime
>     std::uint64_t * res = new (buffer) std::uint64_t;

This starts the lifetime of a new object, but it has indeterminate value.

>     // *res is allowed to be used as it is the correct pointer returned by
> new

The pointer does point to the new object, but derefencing it causes a read of
an indeterminate value, which is undefined behaviour.

>     // *res == 0x3ff0000000000000 // and gives correct value
>     // The very definition of std::launder says that it is suppose to be
> used as:
>     return (*res == *std::launder(reinterpret_cast<std::uint64_t*>(buffer)));

It looks like what you're actually trying to do is:

    alignas(8) std::byte buffer[8];
    new (buffer) double{1};
    std::uint64_t* res = std::start_lifetime_as<std::uint64_t>(buffer);
    return *res == 0x3ff0000000000000;


This is not what std::launder is for.

Reply via email to