[libc++] Fix constexpr-ness of std::tuple's constructor
authorLouis Dionne <ldionne.2@gmail.com>
Fri, 30 Apr 2021 19:52:26 +0000 (15:52 -0400)
committerLouis Dionne <ldionne.2@gmail.com>
Fri, 30 Apr 2021 19:55:10 +0000 (15:55 -0400)
Mentioned in https://reviews.llvm.org/D96523.

libcxx/include/tuple
libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/move_pair.pass.cpp

index 9a58d6a..fa0b6a0 100644 (file)
@@ -466,7 +466,7 @@ public:
             _IsImpDefault<_Tp>... // explicit check
         >::value
     , int> = 0>
-    _LIBCPP_INLINE_VISIBILITY constexpr
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
     tuple()
         _NOEXCEPT_(_And<is_nothrow_default_constructible<_Tp>...>::value)
     { }
@@ -896,7 +896,7 @@ public:
             _EnableImplicitMoveFromPair<_Up1, _Up2, _Tp...>
         >::value
     , int> = 0>
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
     tuple(pair<_Up1, _Up2>&& __p)
         _NOEXCEPT_((_And<
             is_nothrow_constructible<_FirstType<_Tp...>, _Up1>,
@@ -911,7 +911,7 @@ public:
             _EnableExplicitMoveFromPair<_Up1, _Up2, _Tp...>
         >::value
     , int> = 0>
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
     explicit tuple(pair<_Up1, _Up2>&& __p)
         _NOEXCEPT_((_And<
             is_nothrow_constructible<_FirstType<_Tp...>, _Up1>,
index b89a5d4..7428d01 100644 (file)
@@ -47,5 +47,14 @@ int main(int, char**)
         assert(std::get<1>(t1)->id_ == 3);
     }
 
+#if TEST_STD_VER > 11
+    {
+        using pair_t = std::pair<int, char>;
+        constexpr std::tuple<long, long> t(pair_t(0, 'a'));
+        static_assert(std::get<0>(t) == 0, "");
+        static_assert(std::get<1>(t) == 'a', "");
+    }
+#endif
+
   return 0;
 }