From 2b0c7abba35ac2dc8e00c121b93476ff879bfd86 Mon Sep 17 00:00:00 2001 From: Louis Dionne Date: Mon, 1 Apr 2019 16:39:34 +0000 Subject: [PATCH] [libc++] Declare std::tuple_element as struct instead of class MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Similarly to https://reviews.llvm.org/rL350972, this revision changes std::tuple_element from class to struct. Fixes PR41331. Thanks to Jan Wilken Dörrie for the patch. Differential Revision: https://reviews.llvm.org/D60069 llvm-svn: 357411 --- libcxx/include/__tuple | 17 ++++++----------- libcxx/include/array | 5 ++--- libcxx/include/span | 3 +-- libcxx/include/tuple | 4 ++-- libcxx/include/utility | 10 ++++------ .../tuple.helper/tuple.include.array.pass.cpp | 3 +-- .../tuple.tuple/tuple.helper/tuple_element.fail.cpp | 3 +-- .../tuple.tuple/tuple.helper/tuple_element.pass.cpp | 3 +-- .../tuple_size_structured_bindings.pass.cpp | 3 +-- 9 files changed, 19 insertions(+), 32 deletions(-) diff --git a/libcxx/include/__tuple b/libcxx/include/__tuple index 89134b5..0381031 100644 --- a/libcxx/include/__tuple +++ b/libcxx/include/__tuple @@ -53,26 +53,23 @@ template struct _LIBCPP_TEMPLATE_VIS tuple_size : publ template struct _LIBCPP_TEMPLATE_VIS tuple_size : public tuple_size<_Tp> {}; #endif -template class _LIBCPP_TEMPLATE_VIS tuple_element; +template struct _LIBCPP_TEMPLATE_VIS tuple_element; template -class _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, const _Tp> +struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, const _Tp> { -public: typedef typename add_const::type>::type type; }; template -class _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, volatile _Tp> +struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, volatile _Tp> { -public: typedef typename add_volatile::type>::type type; }; template -class _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, const volatile _Tp> +struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, const volatile _Tp> { -public: typedef typename add_cv::type>::type type; }; @@ -281,9 +278,8 @@ using __type_pack_element = typename decltype( #endif template -class _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, __tuple_types<_Types...>> +struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, __tuple_types<_Types...>> { -public: static_assert(_Ip < sizeof...(_Types), "tuple_element index out of range"); typedef __type_pack_element<_Ip, _Types...> type; }; @@ -456,9 +452,8 @@ struct __tuple_assignable<_Tp, _Up, true, true> template -class _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, tuple<_Tp...> > +struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, tuple<_Tp...> > { -public: typedef typename tuple_element<_Ip, __tuple_types<_Tp...> >::type type; }; diff --git a/libcxx/include/array b/libcxx/include/array index 418a2a9..88e9d57 100644 --- a/libcxx/include/array +++ b/libcxx/include/array @@ -91,7 +91,7 @@ template void swap(array& x, array& y) noexcept(noexcept(x.swap(y))); // C++17 template struct tuple_size; -template class tuple_element; +template struct tuple_element; template struct tuple_size>; template struct tuple_element>; template T& get(array&) noexcept; // constexpr in C++14 @@ -433,10 +433,9 @@ struct _LIBCPP_TEMPLATE_VIS tuple_size > : public integral_constant {}; template -class _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, array<_Tp, _Size> > +struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, array<_Tp, _Size> > { static_assert(_Ip < _Size, "Index out of bounds in std::tuple_element<> (std::array)"); -public: typedef _Tp type; }; diff --git a/libcxx/include/span b/libcxx/include/span index 6b89d60..0694f51 100644 --- a/libcxx/include/span +++ b/libcxx/include/span @@ -531,11 +531,10 @@ struct _LIBCPP_TEMPLATE_VIS tuple_size>; // declared b template -class _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, span<_Tp, _Size>> +struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, span<_Tp, _Size>> { static_assert( dynamic_extent != _Size, "std::tuple_element<> not supported for std::span"); static_assert(_Ip < _Size, "Index out of bounds in std::tuple_element<> (std::span)"); -public: typedef _Tp type; }; diff --git a/libcxx/include/tuple b/libcxx/include/tuple index f7e7ee1..335e59e 100644 --- a/libcxx/include/tuple +++ b/libcxx/include/tuple @@ -87,8 +87,8 @@ template struct tuple_size; // undefined template struct tuple_size>; template inline constexpr size_t tuple_size_v = tuple_size::value; // C++17 -template class tuple_element; // undefined -template class tuple_element>; +template struct tuple_element; // undefined +template struct tuple_element>; template using tuple_element_t = typename tuple_element ::type; // C++14 diff --git a/libcxx/include/utility b/libcxx/include/utility index 770d160..3eea6f3 100644 --- a/libcxx/include/utility +++ b/libcxx/include/utility @@ -103,7 +103,7 @@ struct piecewise_construct_t { }; inline constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t(); template struct tuple_size; -template class tuple_element; +template struct tuple_element; template struct tuple_size >; template struct tuple_element<0, pair >; @@ -687,22 +687,20 @@ template : public integral_constant {}; template -class _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, pair<_T1, _T2> > +struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, pair<_T1, _T2> > { static_assert(_Ip < 2, "Index out of bounds in std::tuple_element>"); }; template -class _LIBCPP_TEMPLATE_VIS tuple_element<0, pair<_T1, _T2> > +struct _LIBCPP_TEMPLATE_VIS tuple_element<0, pair<_T1, _T2> > { -public: typedef _T1 type; }; template -class _LIBCPP_TEMPLATE_VIS tuple_element<1, pair<_T1, _T2> > +struct _LIBCPP_TEMPLATE_VIS tuple_element<1, pair<_T1, _T2> > { -public: typedef _T2 type; }; diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple.include.array.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple.include.array.pass.cpp index a97e60c..c3619f7 100644 --- a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple.include.array.pass.cpp +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple.include.array.pass.cpp @@ -11,9 +11,8 @@ // template class tuple; // template -// class tuple_element > +// struct tuple_element > // { -// public: // typedef Ti type; // }; // diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_element.fail.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_element.fail.cpp index 24b735b..7fee551 100644 --- a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_element.fail.cpp +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_element.fail.cpp @@ -11,9 +11,8 @@ // template class tuple; // template -// class tuple_element > +// struct tuple_element > // { -// public: // typedef Ti type; // }; diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_element.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_element.pass.cpp index 5ad2b08..60bbe39 100644 --- a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_element.pass.cpp +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_element.pass.cpp @@ -11,9 +11,8 @@ // template class tuple; // template -// class tuple_element > +// struct tuple_element > // { -// public: // typedef Ti type; // }; diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_structured_bindings.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_structured_bindings.pass.cpp index 00f7ff2..28186a7 100644 --- a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_structured_bindings.pass.cpp +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_structured_bindings.pass.cpp @@ -116,8 +116,7 @@ template int get(Test const&) { static_assert(N == 0, ""); return -1; } template <> -class std::tuple_element<0, Test> { -public: +struct std::tuple_element<0, Test> { typedef int type; }; -- 2.7.4