From e16f2cb6789286dbfa4a184cef25b91dfb499206 Mon Sep 17 00:00:00 2001 From: Louis Dionne Date: Thu, 26 Sep 2019 14:51:10 +0000 Subject: [libc++] Take 2: Implement LWG 2510 Summary: LWG2510 makes tag types like allocator_arg_t explicitly default constructible instead of implicitly default constructible. It also makes the constructors for std::pair and std::tuple conditionally explicit based on the explicit-ness of the default constructibility for the pair/tuple's elements. This was previously committed as r372777 and reverted in r372832 due to the commit breaking LLVM's build in C++14 mode. This issue has now been addressed. Reviewers: mclow.lists Subscribers: christof, jkorous, dexonsmith, libcxx-commits Tags: #libc Differential Revision: https://reviews.llvm.org/D65161 llvm-svn: 372983 --- libcxx/include/tuple | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) (limited to 'libcxx/include/tuple') diff --git a/libcxx/include/tuple b/libcxx/include/tuple index 32bc86913aa..c33b48ab54c 100644 --- a/libcxx/include/tuple +++ b/libcxx/include/tuple @@ -19,7 +19,7 @@ namespace std template class tuple { public: - constexpr tuple(); + explicit(see-below) constexpr tuple(); explicit(see-below) tuple(const T&...); // constexpr in C++14 template explicit(see-below) tuple(U&&...); // constexpr in C++14 @@ -500,8 +500,19 @@ class _LIBCPP_TEMPLATE_VIS tuple struct _CheckArgsConstructor { template - static constexpr bool __enable_default() { - return __all::value...>::value; + static constexpr bool __enable_implicit_default() { + // In C++03, there's no way to implement the resolution of LWG2510. +#ifdef _LIBCPP_CXX03_LANG + return true; +#else + return __all<__is_implicitly_default_constructible<_Args>::value...>::value; +#endif + } + + template + static constexpr bool __enable_explicit_default() { + return __all::value...>::value + && !__enable_implicit_default<_Args...>(); } template @@ -641,11 +652,18 @@ class _LIBCPP_TEMPLATE_VIS tuple const typename tuple_element<_Jp, tuple<_Up...> >::type&& get(const tuple<_Up...>&&) _NOEXCEPT; public: - template ::template __enable_default<_Tp...>() - >::type> - _LIBCPP_INLINE_VISIBILITY - _LIBCPP_CONSTEXPR tuple() + template ::template __enable_implicit_default<_Tp...>() + , void*> = nullptr> + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR + tuple() + _NOEXCEPT_(__all::value...>::value) {} + + template ::template __enable_explicit_default<_Tp...>() + , void*> = nullptr> + explicit _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR + tuple() _NOEXCEPT_(__all::value...>::value) {} tuple(tuple const&) = default; -- cgit v1.2.3