[libcxx-commits] [libcxx] [libc++] Ensure that `std::expected` has no tail padding (PR #69673)
Jan Kokemüller via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Jan 19 10:16:20 PST 2024
================
@@ -88,8 +88,353 @@ _LIBCPP_HIDE_FROM_ABI void __throw_bad_expected_access(_Arg&& __arg) {
# endif
}
+struct __conditional_no_unique_address_invoke_tag {};
----------------
jiixyj wrote:
The constructor with this tag is needed if the type `_Tp` inside the `__conditional_no_unique_address` is neither copyable nor movable. In this case one has to rely on guaranteed copy elision to maneuver the object into place. For example, the `__union_t` type often is neither copyable nor movable and you have to do this dance to construct it:
```c++
: __union_(__conditional_no_unique_address_invoke_tag{},
[&] { return __make_union(__has_val, std::forward<_OtherUnion>(__other)); }),
```
...where previously, without `__conditional_no_unique_address`, one could simply do this:
```c++
: __union_(__make_union(__has_val, std::forward<_OtherUnion>(__other))),
```
I added a comment to the tag type.
https://github.com/llvm/llvm-project/pull/69673
More information about the libcxx-commits
mailing list