diff options
| author | Louis Dionne <ldionne@apple.com> | 2019-09-26 14:51:10 +0000 |
|---|---|---|
| committer | Louis Dionne <ldionne@apple.com> | 2019-09-26 14:51:10 +0000 |
| commit | e16f2cb6789286dbfa4a184cef25b91dfb499206 (patch) | |
| tree | f67676d1b91559354b68e3e9860e0ee4aae2705f /libcxx/include/tuple | |
| parent | 1822087facdfaeac69dcd14690866a4d872e3fdb (diff) | |
| download | bcm5719-llvm-e16f2cb6789286dbfa4a184cef25b91dfb499206.tar.gz bcm5719-llvm-e16f2cb6789286dbfa4a184cef25b91dfb499206.zip | |
[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
Diffstat (limited to 'libcxx/include/tuple')
| -rw-r--r-- | libcxx/include/tuple | 34 |
1 files changed, 26 insertions, 8 deletions
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... T> class tuple { public: - constexpr tuple(); + explicit(see-below) constexpr tuple(); explicit(see-below) tuple(const T&...); // constexpr in C++14 template <class... U> explicit(see-below) tuple(U&&...); // constexpr in C++14 @@ -500,8 +500,19 @@ class _LIBCPP_TEMPLATE_VIS tuple struct _CheckArgsConstructor<true, _Dummy> { template <class ..._Args> - static constexpr bool __enable_default() { - return __all<is_default_constructible<_Args>::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 <class ..._Args> + static constexpr bool __enable_explicit_default() { + return __all<is_default_constructible<_Args>::value...>::value + && !__enable_implicit_default<_Args...>(); } template <class ..._Args> @@ -641,11 +652,18 @@ class _LIBCPP_TEMPLATE_VIS tuple const typename tuple_element<_Jp, tuple<_Up...> >::type&& get(const tuple<_Up...>&&) _NOEXCEPT; public: - template <bool _Dummy = true, class = typename enable_if< - _CheckArgsConstructor<_Dummy>::template __enable_default<_Tp...>() - >::type> - _LIBCPP_INLINE_VISIBILITY - _LIBCPP_CONSTEXPR tuple() + template <bool _Dummy = true, _EnableIf< + _CheckArgsConstructor<_Dummy>::template __enable_implicit_default<_Tp...>() + , void*> = nullptr> + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR + tuple() + _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {} + + template <bool _Dummy = true, _EnableIf< + _CheckArgsConstructor<_Dummy>::template __enable_explicit_default<_Tp...>() + , void*> = nullptr> + explicit _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR + tuple() _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {} tuple(tuple const&) = default; |

