C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Ensure ABI compatibility at runtime -- std::layout_of

From: Giuseppe D'Angelo <giuseppe.dangelo_at_[hidden]>
Date: Thu, 7 Nov 2024 11:35:20 +0100
Il 07/11/24 11:13, Frederick Virchanza Gotham via Std-Proposals ha scritto:

> I thought it might be nice to be able to check this at runtime, something like:
>
> namespace std {
> template<typename T>
> consteval size_t const *layout_of(void);
> }
>
> This function returns a pointer to a null-terminated sequence of
> size_t's as follows:


Will there be any need for this once reflection lands?


> (2) It's possible for two classes to have identical layout but to
> still have differing and incompatible implementations.

Bingo. Say that your magic function tells you that vector<int> is made
up of 3 pointer-sized fields. What are they?

* begin, end, capacity
* begin, end, pointer to physical end
* begin, size, capacity
* begin, size, pointer to metadata/bookkeeping
...


And even if they match, who tells you they're used in a consistent way?

You need something *beyond* C++ to deal with ABI incompatibilities and
with the unsafety of plugin loading in general.


My 2 c,

--
Giuseppe D'Angelo

Received on 2024-11-07 10:35:24