diff --git a/libcxx/include/variant b/libcxx/include/variant index f9098f42249a..6f78e2de1573 100644 --- a/libcxx/include/variant +++ b/libcxx/include/variant @@ -1156,29 +1156,24 @@ public: : __impl(in_place_index<_Ip>, _VSTD::forward<_Arg>(__arg)) {} template , - class _Tp = variant_alternative_t<_Ip, variant<_Types...>>, - enable_if_t, int> = 0> + enable_if_t<(_Ip < sizeof...(_Types)), size_t> _Ip2 = _Ip, + class _Tp = variant_alternative_t<_Ip2, variant<_Types...>>, + enable_if_t::value, int> = 0> inline _LIBCPP_INLINE_VISIBILITY - explicit constexpr variant( - in_place_index_t<_Ip>, - _Args&&... __args) noexcept(is_nothrow_constructible_v<_Tp, _Args...>) + explicit constexpr variant(in_place_index_t<_Ip>, + _Args&&... __args) + noexcept(is_nothrow_constructible_v<_Tp, _Args...>) : __impl(in_place_index<_Ip>, _VSTD::forward<_Args>(__args)...) {} - template < - size_t _Ip, - class _Up, - class... _Args, - enable_if_t<(_Ip < sizeof...(_Types)), int> = 0, - class _Tp = variant_alternative_t<_Ip, variant<_Types...>>, + template _Ip2 = _Ip, + class _Tp = variant_alternative_t<_Ip2, variant<_Types...>>, enable_if_t&, _Args...>, int> = 0> inline _LIBCPP_INLINE_VISIBILITY - explicit constexpr variant( - in_place_index_t<_Ip>, - initializer_list<_Up> __il, - _Args&&... __args) noexcept( - is_nothrow_constructible_v<_Tp, initializer_list<_Up>&, _Args...>) + explicit constexpr variant(in_place_index_t<_Ip>, initializer_list<_Up> __il, + _Args&&... __args) + noexcept(is_nothrow_constructible_v<_Tp, initializer_list<_Up>&, _Args...>) : __impl(in_place_index<_Ip>, __il, _VSTD::forward<_Args>(__args)...) {} template < diff --git a/libcxx/test/std/utilities/variant/variant.variant/variant.ctor/in_place_index_init_list_args.pass.cpp b/libcxx/test/std/utilities/variant/variant.variant/variant.ctor/in_place_index_init_list_args.pass.cpp index 608cdf9d6efb..9d0bf55fb538 100644 --- a/libcxx/test/std/utilities/variant/variant.variant/variant.ctor/in_place_index_init_list_args.pass.cpp +++ b/libcxx/test/std/utilities/variant/variant.variant/variant.ctor/in_place_index_init_list_args.pass.cpp @@ -73,6 +73,12 @@ void test_ctor_sfinae() { !std::is_constructible, IL>::value, ""); static_assert(!test_convertible, IL>(), ""); } + { // index not in variant + using V = std::variant; + static_assert( + !std::is_constructible, IL>::value, ""); + static_assert(!test_convertible, IL>(), ""); + } } void test_ctor_basic() {