libstdc++ apparently does not implement P0602 “variant and optional should propagate copy/move triviality”. You can verify this with:
static_assert(std::is_trivially_copyable_v<std::optional<int>>);
which fails for libstdc++, and passes for libc++ and the MSVC standard library (which really needs a proper name so we don’t have to call it either “The MSVC implementation of the C++ standard library” or “The MSVC STL”).
Of course MSVC still won’t pass an optional<int>
in a register because the MS ABI.
EDIT: This issue has been fixed in the GCC 8 release series.