Implement LWG issue 2275 'forward_as_tuple should be constexpr'

llvm-svn: 192038
Cr-Mirrored-From: sso://chromium.googlesource.com/_direct/external/github.com/llvm/llvm-project
Cr-Mirrored-Commit: de9320aa2b1fa3a77ba656d227310e24e974ff3f
diff --git a/include/tuple b/include/tuple
index 5fa6ef3..9f716fb 100644
--- a/include/tuple
+++ b/include/tuple
@@ -73,7 +73,7 @@
 const unspecified ignore;
 
 template <class... T> tuple<V...>  make_tuple(T&&...); // constexpr in C++14
-template <class... T> tuple<ATypes...> forward_as_tuple(T&&...) noexcept;
+template <class... T> tuple<ATypes...> forward_as_tuple(T&&...) noexcept; // constexpr in C++14
 template <class... T> tuple<T&...> tie(T&...) noexcept;
 template <class... Tuples> tuple<CTypes...> tuple_cat(Tuples&&... tpls); // constexpr in C++14
   
@@ -833,14 +833,6 @@
 template <class... _Tp>
 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
 tuple<_Tp&&...>
-__forward_as_tuple(_Tp&&... __t) _NOEXCEPT
-{
-    return tuple<_Tp&&...>(_VSTD::forward<_Tp>(__t)...);
-}
-
-template <class... _Tp>
-inline _LIBCPP_INLINE_VISIBILITY
-tuple<_Tp&&...>
 forward_as_tuple(_Tp&&... __t) _NOEXCEPT
 {
     return tuple<_Tp&&...>(_VSTD::forward<_Tp>(__t)...);
@@ -1041,7 +1033,7 @@
     typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&>::type
     operator()(tuple<_Types...> __t, _Tuple0&& __t0)
     {
-        return __forward_as_tuple(_VSTD::forward<_Types>(get<_I0>(__t))...,
+        return forward_as_tuple(_VSTD::forward<_Types>(get<_I0>(__t))...,
                                       get<_J0>(_VSTD::forward<_Tuple0>(__t0))...);
     }
 
@@ -1056,7 +1048,7 @@
            tuple<_Types..., typename __apply_cv<_Tuple0, typename tuple_element<_J0, _T0>::type>::type&&...>,
            typename __make_tuple_indices<sizeof ...(_Types) + tuple_size<_T0>::value>::type,
            typename __make_tuple_indices<tuple_size<_T1>::value>::type>()
-                           (__forward_as_tuple(
+                           (forward_as_tuple(
                               _VSTD::forward<_Types>(get<_I0>(__t))...,
                               get<_J0>(_VSTD::forward<_Tuple0>(__t0))...
                             ),
diff --git a/test/utilities/tuple/tuple.tuple/tuple.creation/forward_as_tuple.pass.cpp b/test/utilities/tuple/tuple.tuple/tuple.creation/forward_as_tuple.pass.cpp
index 148850e..5e84ff8 100644
--- a/test/utilities/tuple/tuple.tuple/tuple.creation/forward_as_tuple.pass.cpp
+++ b/test/utilities/tuple/tuple.tuple/tuple.creation/forward_as_tuple.pass.cpp
@@ -51,6 +51,15 @@
     assert(std::get<1>(t) == 'a');
 }
 
+#if _LIBCPP_STD_VER > 11
+template <class Tuple>
+constexpr int 
+test3(const Tuple& t)
+{
+    return std::tuple_size<Tuple>::value;
+}
+#endif
+
 int main()
 {
     {
@@ -67,5 +76,8 @@
         double i = 2.5;
         char c = 'a';
         test2a(std::forward_as_tuple(i, c));
+#if _LIBCPP_STD_VER > 11
+        static_assert ( test3 (std::forward_as_tuple(i, c)) == 2, "" );
+#endif
     }
 }