[libcxx-commits] [libcxx] [libc++] Fix UB in <expected> related to "has value" flag (#68552) (PR #68733)
Jan Kokemüller via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Oct 17 18:32:36 PDT 2023
================
@@ -893,11 +854,15 @@ class expected {
}
private:
- struct __empty_t {};
----------------
jiixyj wrote:
And previously, this was needed when the `expected` was initialized like this (pseudo code):
```c++
expected(const expected& other) : union_(), has_value_(other.has_value_) {
// `std::construct_at` into `union_`
}
```
...but now, the union is never value-initialized any longer. All `expected` constructors will either initialize value or error, and make use of the member initializer list:
```c++
expected(const expected& other) : union_(other.has_value_, other.union_), has_value_(other.has_value_) { }
```
https://github.com/llvm/llvm-project/pull/68733
More information about the libcxx-commits
mailing list