[libcxx-commits] [libcxx] [libc++] Fix UB in <expected> related to "has value" flag (#68552) (PR #68733)
via libcxx-commits
libcxx-commits at lists.llvm.org
Sat Oct 14 14:27:34 PDT 2023
================
@@ -136,14 +134,7 @@ class expected {
noexcept(is_nothrow_copy_constructible_v<_Tp> && is_nothrow_copy_constructible_v<_Err>) // strengthened
requires(is_copy_constructible_v<_Tp> && is_copy_constructible_v<_Err> &&
!(is_trivially_copy_constructible_v<_Tp> && is_trivially_copy_constructible_v<_Err>))
- : __has_val_(__other.__has_val_) {
- if (__has_val_) {
- std::construct_at(std::addressof(__union_.__val_), __other.__union_.__val_);
- } else {
- std::construct_at(std::addressof(__union_.__unex_), __other.__union_.__unex_);
- }
- }
-
+ : __union_(__union_from_expected(__other)), __has_val_(__other.__has_val_) { }
----------------
huixie90 wrote:
I wonder if this function call introduces extra move/copy of the `__union_t`. What about making this function `__union_from_expected` a constructor of the `__union_t`
https://github.com/llvm/llvm-project/pull/68733
More information about the libcxx-commits
mailing list