https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121610
Bug ID: 121610
Summary: Specialize std::optional<std::indirect<T>> and
std::optional<std::polymorphic<T>>
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Keywords: ABI
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: redi at gcc dot gnu.org
Target Milestone: ---
For types with nothrow move, indirect::valueless_after_move and
polymorphic::valueless_after_move are always false, and so the types always
contain a value. That means that optional<indirect<T>> can unconditionally
construct an indirect<T> object (instead of using all the nested union
implementation complexity) and use its null state for the "does not contain a
value" property of the std::optional.
This will result in a much simpler (and so faster to compile) std::optional
specialization, but more importantly it avoids needing the bool _M_is_engaged
member, reducing the size of the optional by alignof(indirect<T>).