[libcxx-commits] [libcxx] [libc++] Fix UB in <expected> related to "has value" flag (#68552) (PR #68733)
A. Jiang via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Oct 16 20:26:53 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/68733/libcxx at github.com>
frederick-vs-ja wrote:
> You can't expect that everything works if you have a potentially overlapping subobject and then destroy and construct it.
In the standard wording, there's no `[[no_unique_address]]` added to _`val`_ or _`unex`_ of `expected` ([[expected.object.general]](https://eel.is/c++draft/expected.object.general), [[expected.void.general]](https://eel.is/c++draft/expected.void.general)).
Per [[objects.within.classes]/3](https://eel.is/c++draft/objects.within.classes#3), IMO it's possible to say that `value()` and `error()` are required to as-if return references to non-potentially-overlapping subobjects.
> If that were valid we also wouldn't be allowed to EBO the deleter of `unique_ptr`s
IIUC we are allowed. There's no exposition-only data member mentioned in [[unique.ptr.single]](https://eel.is/c++draft/unique.ptr.single) and [[unique.ptr.runtime]](https://eel.is/c++draft/unique.ptr.runtime), so implementations are free to use EBO for the deleter object or not to do so.
The difference seems to be that exposition-only members are specified for `expected` but not `unique_ptr`.
https://github.com/llvm/llvm-project/pull/68733
More information about the libcxx-commits
mailing list