https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124121
--- Comment #19 from Jan Schultke <janschultke at googlemail dot com> --- (In reply to Jonathan Wakely from comment #18) > (In reply to [email protected] from comment #15) > What inplace_vector does is use a union to reserve storage for an array > without creating that array. It's a union with no active member. That works > fine when we do it for a single object like in std::optional<T>, but here we > want to do it for T[N]. Currently the C++ standard makes this very difficult > (because usually when you define an array, of course you want its subobjects > to be defined as well). I agree, and maybe some additional standard features are needed. Maybe what the standard needs is a "shallow form" of std::start_lifetime_as that does not begin the lifetimes of any aggregate members (unlike std::start_lifetime_as) and that does not begin the lifetime of any subobjects implicitly. That hypothetical "constexpr std::start_lifetime_as_aggregate" would solve the optimization problem in the runtime case (since it affects zero non-padding bytes of memory; it only starts the lifetime of the containing struct or array). It would also solve the restriction that only trivial types can be used at compile time. After all, there's no obvious reason why you couldn't begin the lifetime of the union alternative (without initialization of its elements) during constant evaluation.
