Cleaning up some tuple code.

llvm-svn: 114848
Cr-Mirrored-From: sso://chromium.googlesource.com/_direct/external/github.com/llvm/llvm-project
Cr-Mirrored-Commit: 30ad985b6b427da2459e7231190774fffbb81f3c
diff --git a/include/tuple b/include/tuple
index 5ec0f81..2c29495 100644
--- a/include/tuple
+++ b/include/tuple
@@ -193,18 +193,21 @@
         {static_assert(!is_reference<_Hp>::value,
               "Attempted to default construct a reference element in a tuple");}
 
-    template <class _Tp>
+    template <class _Tp,
+              class = typename enable_if<is_constructible<_Hp, _Tp>::value>::type>
         _LIBCPP_INLINE_VISIBILITY
         explicit __tuple_leaf(_Tp&& __t)
             : value(_STD::forward<_Tp>(__t))
-        {static_assert(!is_lvalue_reference<_Hp>::value ||
+        {static_assert(!is_reference<_Hp>::value ||
                         is_lvalue_reference<_Hp>::value &&
                         (is_lvalue_reference<_Tp>::value ||
                          is_same<typename remove_reference<_Tp>::type,
                                  reference_wrapper<
                                     typename remove_reference<_Hp>::type
                                  >
-                                >::value),
+                                >::value) ||
+                        (is_rvalue_reference<_Hp>::value &&
+                         !is_lvalue_reference<_Tp>::value),
        "Attempted to construct a reference element in a tuple with an rvalue");}
 
     template <class _Tp, class _Alloc>
@@ -249,6 +252,10 @@
                                 >::value),
        "Attempted to construct a reference element in a tuple with an rvalue");}
 
+    __tuple_leaf(const __tuple_leaf& __t)
+        : value(__t.get())
+        {static_assert(!is_rvalue_reference<_Hp>::value, "Can not copy a tuple with rvalue reference member");}
+
     template <class _Tp>
         _LIBCPP_INLINE_VISIBILITY
         explicit __tuple_leaf(const __tuple_leaf<_Ip, _Tp>& __t)
@@ -297,7 +304,8 @@
         __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
             : _Hp(__a) {}
 
-    template <class _Tp>
+    template <class _Tp,
+              class = typename enable_if<is_constructible<_Hp, _Tp>::value>::type>
         _LIBCPP_INLINE_VISIBILITY
         explicit __tuple_leaf(_Tp&& __t)
             : _Hp(_STD::forward<_Tp>(__t)) {}