[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
       
    Sat Oct 21 00:36:03 PDT 2023
    
    
  
jiixyj wrote:
> Yes, that would be invalid. You need to apply `std::construct_at` to the `repr` member itself, not to the value inside the union.
Ahh, so when `emplace()`ing the `expected`, you would always transparently replace the whole `repr` struct? Would the destructor of `repr` still be allowed to call `std::destroy_at` on its union member like this, even though they are partially overlapping?
```c++
~repr() {
  if (__has_val_) {
    std::destroy_at(std::addressof(__union_.__val_));
  } else {
    std::destroy_at(std::addressof(__union_.__unex_));
  }
}
```
https://github.com/llvm/llvm-project/pull/69673
    
    
More information about the libcxx-commits
mailing list