On Sat, Feb 1, 2020 at 4:46 PM Anton Bikineev <ant.bikineev@gmail.com> wrote:
Or, even better, remove definition of `optional()` to make it trivially-default-constructible?
Removing the definition of optional() (or in general having it not user-provided) makes itĀ deletedĀ for T that have non-trivial default constructor (since T is in union).

but I still don't see a reason to value-initialize `dummy`.
Value-initialization appears to be needed for the constructor to be constexpr.
It seems to me that `optional` is not usable in compile-time before C++20, because switching union active member is not allowed, and so it doesn't make sense to mark `optional()` as constexpr, but maybe I have missed something.
A slightly offtopic question: why in your initial example `dummy` is an array? If it's a single object, pessimization due to zero-initialization will be reduced (https://godbolt.org/z/PxDR8J).

--
Andrey Davydov