diff --git a/libcxx/include/variant b/libcxx/include/variant --- a/libcxx/include/variant +++ b/libcxx/include/variant @@ -203,7 +203,6 @@ #include <__config> #include <__utility/forward.h> #include <__tuple> -#include #include #include #include @@ -238,6 +237,19 @@ // Remove this once we drop support for GCC 5. #if _LIBCPP_STD_VER > 14 && !(defined(_LIBCPP_COMPILER_GCC) && _GNUC_VER_NEW < 6000) +// In all the places that __light_array is used, _Tp is always a function pointer or +// a __light_array. +template +struct __light_array { + static_assert(_Size > 0, "Did you expect an element to be stored?"); + _Tp __buf_[_Size] = {}; + + _LIBCPP_INLINE_VISIBILITY constexpr + const _Tp &operator[](size_t __n) const noexcept { + return __buf_[__n]; + } +}; + _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS @@ -498,7 +510,7 @@ template inline _LIBCPP_INLINE_VISIBILITY - static constexpr auto&& __at(const array<_Tp, _Np>& __elems, + static constexpr auto&& __at(const __light_array<_Tp, _Np>& __elems, size_t __index, _Indices... __indices) { return __at(__elems[__index], __indices...); } @@ -514,7 +526,7 @@ inline _LIBCPP_INLINE_VISIBILITY static constexpr auto __make_farray(_Fs&&... __fs) { __std_visit_visitor_return_type_check<__uncvref_t<_Fs>...>(); - using __result = array...>, sizeof...(_Fs)>; + using __result = __light_array...>, sizeof...(_Fs)>; return __result{{_VSTD::forward<_Fs>(__fs)...}}; }