[libcxx-commits] [libcxx] [libc++] P2255R2: Add deleted tuple constructor overloads (PR #205379)

Yihan Wang via libcxx-commits libcxx-commits at lists.llvm.org
Sat Aug 15 02:06:57 PDT 2026


================
@@ -616,21 +616,83 @@ public:
               _Not<_IsThisTuple<_Up...> >, // extension to allow mis-behaved user constructors
               is_constructible<_Tp, _Up>... > {};
 
-  template <class... _Up,
-            __enable_if_t< _And< _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>, _EnableUTypesCtor<_Up...> >::value,
-                           int> = 0>
+  template <class... _Up>
+  struct _EnableUTypesCtorBase : _And<_BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>, _EnableUTypesCtor<_Up...> > {};
+
+  template <bool, class... _Up>
+  struct _EnableUTypesCtorNoDangling : false_type {};
+
+#    if _LIBCPP_STD_VER >= 23
+  template <class... _Up>
+  static constexpr bool __has_danglings() {
+    if constexpr (sizeof...(_Up) == sizeof...(_Tp))
+      return (__reference_constructs_from_temporary_v<_Tp, _Up&&> || ...);
+    else
+      return false;
+  }
+
+  template <class _Source, class _DecayedSource = __remove_cvref_t<_Source> >
+  static inline constexpr bool __has_danglings_from_tuple_like = false;
+
+  template <class _Source, class... _Up>
+  static inline constexpr bool __has_danglings_from_tuple_like<_Source, tuple<_Up...> > =
+      __has_danglings<__copy_cvref_t<_Source, _Up>...>();
+
+  template <class _Source, class _U1, class _U2>
+  static inline constexpr bool __has_danglings_from_tuple_like<_Source, pair<_U1, _U2> > =
+      __has_danglings<__copy_cvref_t<_Source, _U1>, __copy_cvref_t<_Source, _U2> >();
+
+  template <bool __dangles, class _CtorEnabled>
+  static inline constexpr bool __check_danglings_from_constructor = false;
+
+  template <class _CtorEnabled>
+  static inline constexpr bool __check_danglings_from_constructor<true, _CtorEnabled> = _CtorEnabled::value;
+
+  template <bool __dangles, class _CtorEnabled>
+  static inline constexpr bool __check_no_danglings_from_constructor = _CtorEnabled::value;
+
+  template <class _CtorEnabled>
+  static inline constexpr bool __check_no_danglings_from_constructor<true, _CtorEnabled> = false;
+
+  template <class... _Up>
+  static inline constexpr bool __has_danglings_from_utypes =
+      __check_danglings_from_constructor<__has_danglings<_Up...>(), _EnableUTypesCtorBase<_Up...> >;
+
+  template <class... _Up>
+  static inline constexpr bool __has_no_danglings_from_utypes =
+      __check_no_danglings_from_constructor<__has_danglings<_Up...>(), _EnableUTypesCtorBase<_Up...> >;
+#    endif // _LIBCPP_STD_VER >= 23
+
+  template <class... _Up>
+  static inline constexpr bool __enable_utypes_constructor_no_dangling() {
----------------
yronglin wrote:

Done.

https://github.com/llvm/llvm-project/pull/205379


More information about the libcxx-commits mailing list