C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Replace an object -- but retain old object if new object fails to construct

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Tue, 28 Oct 2025 10:44:14 +0000
On Fri, Oct 24, 2025 at 5:00 PM Arthur O'Dwyer wrote:
>
> There's actually a proposal out right now, D3858 `restart_lifetime<T>`,
> which can be viewed as a "rehydrate" operation specific to each type
> whose "dehydrate" operation is trivial.
> https://quuxplusone.github.io/blog/2025/10/18/thoughts-on-p3858r0/


I had a look at your blog link, specifically the following excerpt:

"P3858 restart_lifetime needs to work on arbitrary 'trivially
relocatable' types, and must be able to have a physical effect. For
example, on ARM64e, calling restart_lifetime<Animal>(&a) must replace
(and cryptographically re-sign) the vptr of a."

with the following code example:

    template<class T>
    T* trivially_relocate(T* first, T* last, T* result)
    {
      static_assert(std::is_trivially_relocatable_v<T>);
     static_assert(!std::is_const_v<T>);

     std::memcpy(result, first, (last - first) * sizeof(T));
     for (size_t i = 0; i < (last - first); ++i)
       std::restart_lifetime<T>(result[i]);
     return result + (last - first);
    }

So if I understand correctly, the following static_assert will always
fail on arm64e?

    static_assert( is_polymorphic_v<T> && is_trivially_relocatable_v<T> );

Specifically what I'm saying, is that for every class that is
polymorphic (i.e. every class that has a vtable, and for which every
object contains a vtable pointer), an object of the class cannot be
trivially relocated? Reason being that you need to re-encrypt the
vtable pointer if the object's base address moves. Do I understand
correctly?

arm64e throws a spanner in the works for a few other things too. I was
trying to devise a way to do more with a pointer to a polymorphic
object:

    https://www.virjacode.com/papers/polyhandle.htm

I haven't given up totally yet though.

Received on 2025-10-28 10:44:01