Skip to content

Commit 7d15ece

Browse files
mparkldionne
authored andcommitted
[libcxx/variant] Implement workaround for GCC bug.
A parameter pack is deemed to be uncaptured, which is bogus... but it seems to be because it's within an expression that involves `decltype` of an uncaptured pack or something: https://godbolt.org/z/b8z3sh Drive-by fix for uglified name. Differential Revision: https://reviews.llvm.org/D86827
1 parent 2d3e128 commit 7d15ece

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

libcxx/include/variant

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -537,25 +537,32 @@ static constexpr auto __make_vtable(_Fp __f) {
537537
}
538538

539539
struct __base {
540+
template <class _Vis, class... _Vs>
541+
struct __dispatch {
542+
template <size_t... _Is>
543+
inline _LIBCPP_INLINE_VISIBILITY
544+
constexpr auto operator()(integral_constant<size_t, _Is>...) const noexcept {
545+
return +[](_Vis&& __vis, _Vs&&... __vs) -> decltype(auto) {
546+
return __invoke_constexpr(
547+
_VSTD::forward<_Vis>(__vis),
548+
__access::__base::__get_alt<_Is>(_VSTD::forward<_Vs>(__vs))...);
549+
};
550+
}
551+
};
552+
540553
template <class _Vis, class _Vp, class _Wp>
541554
inline _LIBCPP_INLINE_VISIBILITY
542555
static constexpr decltype(auto)
543556
__visit_alt_at(size_t __index, _Vis&& __vis, _Vp&& __v, _Wp&& __w) {
544557
constexpr size_t __size = __uncvref_t<_Vp>::__size();
545558
static_assert(__size == __uncvref_t<_Wp>::__size());
546-
constexpr auto __dispatch = [](auto __i) {
547-
return +[](_Vis&& __vis_, _Vp&& __v_, _Wp&& __w_) -> decltype(auto) {
548-
constexpr size_t _Ip = decltype(__i)::value;
549-
return __invoke_constexpr(
550-
_VSTD::forward<_Vis>(__vis_),
551-
__access::__base::__get_alt<_Ip>(_VSTD::forward<_Vp>(__v_)),
552-
__access::__base::__get_alt<_Ip>(_VSTD::forward<_Wp>(__w_)));
553-
};
559+
constexpr auto __dispatch_at = [](auto __i) {
560+
return __dispatch<_Vis, _Vp, _Wp>{}(__i, __i);
554561
};
555562
#define _LIBCPP_VARIANT_CASE(_Ip) \
556563
case _Ip: { \
557564
if constexpr (_Ip < __size) { \
558-
return __dispatch(integral_constant<size_t, _Ip>{})( \
565+
return __dispatch_at(integral_constant<size_t, _Ip>{})( \
559566
_VSTD::forward<_Vis>(__vis), \
560567
_VSTD::forward<_Vp>(__v), \
561568
_VSTD::forward<_Wp>(__w)); \
@@ -569,7 +576,7 @@ struct __base {
569576
default: __throw_bad_variant_access();
570577
}
571578
} else {
572-
constexpr auto __vtable = __make_vtable<__size>(__dispatch);
579+
constexpr auto __vtable = __make_vtable<__size>(__dispatch_at);
573580
return __vtable[__index + 1](_VSTD::forward<_Vis>(__vis),
574581
_VSTD::forward<_Vp>(__v),
575582
_VSTD::forward<_Wp>(__w));
@@ -594,14 +601,7 @@ struct __base {
594601
static constexpr decltype(auto)
595602
__visit_alt_impl(index_sequence<_Is...>, _Vis&& __vis, _Vs&&... __vs) {
596603
using __multi = __multi<__uncvref_t<_Vs>::__size()...>;
597-
constexpr auto __dispatch = [](auto... __is) {
598-
return +[](_Vis&& __vis_, _Vs&&... __vs_) -> decltype(auto) {
599-
return __invoke_constexpr(
600-
_VSTD::forward<_Vis>(__vis_),
601-
__access::__base::__get_alt<decltype(__is)::value>(
602-
_VSTD::forward<_Vs>(__vs_))...);
603-
};
604-
};
604+
constexpr __dispatch<_Vis, _Vs...> __dispatch;
605605
#define _LIBCPP_VARIANT_CASE(_Ip) \
606606
case _Ip: { \
607607
if constexpr (_Ip < __multi::__size) { \
@@ -874,9 +874,9 @@ protected:
874874
template <size_t _Ip, class _Tp, class... _Args>
875875
inline _LIBCPP_INLINE_VISIBILITY
876876
static _Tp& __construct_alt(__alt<_Ip, _Tp>& __a, _Args&&... __args) {
877-
auto* result = ::new ((void*)_VSTD::addressof(__a))
877+
auto* __result = ::new ((void*)_VSTD::addressof(__a))
878878
__alt<_Ip, _Tp>(in_place, _VSTD::forward<_Args>(__args)...);
879-
return result->__value;
879+
return __result->__value;
880880
}
881881

882882
template <class _Rhs>

0 commit comments

Comments
 (0)