Date: Tue, 28 Oct 2025 13:04:54 +0100
Il 28/10/25 11:44, Frederick Virchanza Gotham via Std-Proposals ha scritto:
> 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));
This needs to be std::memmove, as first/last/result may overlap.
> 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?
That is not correct.
The current specification allows for trivial relocation of polymorphic
types, on *any* platform. Polymorphism simply isn't taken into account
when deciding whether a class is trivially relocatable or not:
struct PolyTR {
virtual void f();
};
static_assert( std::is_polymorphic_v<PolyTR> );
static_assert( std::is_trivially_relocatable_v<PolyTR> ); // OK, everywhere
My 2 c,
--
Giuseppe D'Angelo
> 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));
This needs to be std::memmove, as first/last/result may overlap.
> 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?
That is not correct.
The current specification allows for trivial relocation of polymorphic
types, on *any* platform. Polymorphism simply isn't taken into account
when deciding whether a class is trivially relocatable or not:
struct PolyTR {
virtual void f();
};
static_assert( std::is_polymorphic_v<PolyTR> );
static_assert( std::is_trivially_relocatable_v<PolyTR> ); // OK, everywhere
My 2 c,
--
Giuseppe D'Angelo
Received on 2025-10-28 12:04:57
