[libcxx-commits] [libcxx] [libc++] Ensure that `std::expected` has no tail padding (PR #69673)
Richard Smith via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Oct 20 11:24:02 PDT 2023
Jan =?utf-8?q?Kokemüller?= <jan.kokemueller at gmail.com>,
Jan =?utf-8?q?Kokemüller?= <jan.kokemueller at gmail.com>,
Jan =?utf-8?q?Kokemüller?= <jan.kokemueller at gmail.com>,
Jan =?utf-8?q?Kokemüller?= <jan.kokemueller at gmail.com>
Message-ID:
In-Reply-To: <llvm/llvm-project/pull/69673/libcxx at github.com>
zygoloid wrote:
> If you don't want to rely on a language extension, the rule you need to conform to is that you can't transparently replace a potentially overlapping subboject -- you can't use `construct_at` on a base class or a `[[no_unique_address]]` member.
Here's one approach you could take:
```
template<typename T, typename E> struct expected {
struct repr_type {
[[no_unique_address]] union {
[[no_unique_address]] T value;
[[no_unique_address]] E error;
};
bool is_error;
} repr;
};
```
... then apply `std::construct_at` to the `repr` member from `emplace`.
https://github.com/llvm/llvm-project/pull/69673
More information about the libcxx-commits
mailing list