[libc++] `optional<T&>` is a structural type
Currently, the internal pointer in libc++'s optional<T&> is a public member, which makes optional<T&> a structural type. As a result, the following code snippet is well-formed when using libc++, which doesn't seem intended. Godbolt link.
#include <optional>
#include <utility>
inline constexpr int num = 42;
void test() {
(void)std::cw<std::optional<const int&>{num}>;
}
This is possibly a bug as [objects.within.classes]/3 requires "equivalent observable behavior", while currently a private data member certainly makes the class non-structural.
However, it seems desired making optional a structural type (see P2484 and P3380), and when optional<T&> is guaranteed to be a structural type, the intended behavior is probably equivalent to having a public pointer member, which is what libc++ currently does.
Do we want to keep the status quo (i.e. keeping the member public) and document this as an extension, or make the member private?
CC @smallp-o-p @ldionne @philnik777.
IMO we should make it private. I don't think it's worth having an extension here, especially since this is a quite niche use-case.
Whoops. Overlooked that.