[libcxx-commits] [libcxx] [libc++] Remove __dependent_type (PR #167119)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Sat Nov 8 02:21:00 PST 2025
https://github.com/philnik777 created https://github.com/llvm/llvm-project/pull/167119
None
>From 0994a6b1e77fadb92ce1e1742e60a6b0a363f9ba Mon Sep 17 00:00:00 2001
From: Nikolas Klauser <nikolasklauser at berlin.de>
Date: Sat, 8 Nov 2025 11:19:15 +0100
Subject: [PATCH] [libc++] Remove __dependent_type
---
libcxx/include/CMakeLists.txt | 1 -
libcxx/include/__memory/unique_ptr.h | 113 ++++++------------
libcxx/include/__type_traits/dependent_type.h | 25 ----
libcxx/include/module.modulemap.in | 1 -
libcxx/include/variant | 11 +-
5 files changed, 43 insertions(+), 108 deletions(-)
delete mode 100644 libcxx/include/__type_traits/dependent_type.h
diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 57032ce26d4fd..8f0547be54e1c 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -801,7 +801,6 @@ set(files
__type_traits/copy_cvref.h
__type_traits/datasizeof.h
__type_traits/decay.h
- __type_traits/dependent_type.h
__type_traits/desugars_to.h
__type_traits/detected_or.h
__type_traits/disjunction.h
diff --git a/libcxx/include/__memory/unique_ptr.h b/libcxx/include/__memory/unique_ptr.h
index eff24546cdc01..43c12a674d2b5 100644
--- a/libcxx/include/__memory/unique_ptr.h
+++ b/libcxx/include/__memory/unique_ptr.h
@@ -27,7 +27,6 @@
#include <__type_traits/add_reference.h>
#include <__type_traits/common_type.h>
#include <__type_traits/conditional.h>
-#include <__type_traits/dependent_type.h>
#include <__type_traits/enable_if.h>
#include <__type_traits/integral_constant.h>
#include <__type_traits/is_array.h>
@@ -98,28 +97,6 @@ inline const bool __is_default_deleter_v = false;
template <class _Tp>
inline const bool __is_default_deleter_v<default_delete<_Tp> > = true;
-template <class _Deleter>
-struct __unique_ptr_deleter_sfinae {
- static_assert(!is_reference<_Deleter>::value, "incorrect specialization");
- typedef const _Deleter& __lval_ref_type;
- typedef _Deleter&& __good_rval_ref_type;
- typedef true_type __enable_rval_overload;
-};
-
-template <class _Deleter>
-struct __unique_ptr_deleter_sfinae<_Deleter const&> {
- typedef const _Deleter& __lval_ref_type;
- typedef const _Deleter&& __bad_rval_ref_type;
- typedef false_type __enable_rval_overload;
-};
-
-template <class _Deleter>
-struct __unique_ptr_deleter_sfinae<_Deleter&> {
- typedef _Deleter& __lval_ref_type;
- typedef _Deleter&& __bad_rval_ref_type;
- typedef false_type __enable_rval_overload;
-};
-
#if defined(_LIBCPP_ABI_ENABLE_UNIQUE_PTR_TRIVIAL_ABI)
# define _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI __attribute__((__trivial_abi__))
#else
@@ -151,23 +128,9 @@ class _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI unique_ptr {
private:
_LIBCPP_COMPRESSED_PAIR(pointer, __ptr_, deleter_type, __deleter_);
- using _DeleterSFINAE _LIBCPP_NODEBUG = __unique_ptr_deleter_sfinae<_Dp>;
-
- template <bool _Dummy>
- using _LValRefType _LIBCPP_NODEBUG = typename __dependent_type<_DeleterSFINAE, _Dummy>::__lval_ref_type;
-
template <bool _Dummy>
- using _GoodRValRefType _LIBCPP_NODEBUG = typename __dependent_type<_DeleterSFINAE, _Dummy>::__good_rval_ref_type;
-
- template <bool _Dummy>
- using _BadRValRefType _LIBCPP_NODEBUG = typename __dependent_type<_DeleterSFINAE, _Dummy>::__bad_rval_ref_type;
-
- template <bool _Dummy, class _Deleter = typename __dependent_type< __type_identity<deleter_type>, _Dummy>::type>
using _EnableIfDeleterDefaultConstructible _LIBCPP_NODEBUG =
- __enable_if_t<is_default_constructible<_Deleter>::value && !is_pointer<_Deleter>::value>;
-
- template <class _ArgType>
- using _EnableIfDeleterConstructible _LIBCPP_NODEBUG = __enable_if_t<is_constructible<deleter_type, _ArgType>::value>;
+ __enable_if_t<is_default_constructible<deleter_type>::value && !is_pointer<deleter_type>::value>;
template <class _UPtr, class _Up>
using _EnableIfMoveConvertible _LIBCPP_NODEBUG =
@@ -193,20 +156,27 @@ class _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI unique_ptr {
: __ptr_(__p),
__deleter_() {}
- template <bool _Dummy = true, class = _EnableIfDeleterConstructible<_LValRefType<_Dummy> > >
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(pointer __p, _LValRefType<_Dummy> __d) _NOEXCEPT
+ template <bool _Dummy = true,
+ __enable_if_t<_Dummy && is_constructible<deleter_type, const deleter_type&>::value, int> = 0>
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(pointer __p, const deleter_type& __d) _NOEXCEPT
: __ptr_(__p),
__deleter_(__d) {}
- template <bool _Dummy = true, class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy> > >
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(pointer __p, _GoodRValRefType<_Dummy> __d) _NOEXCEPT
+ template <bool _Dummy = true,
+ __enable_if_t<_Dummy && !is_reference<deleter_type>::value &&
+ is_constructible<deleter_type, deleter_type&&>::value,
+ int> = 0>
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(pointer __p, deleter_type&& __d) _NOEXCEPT
: __ptr_(__p),
__deleter_(std::move(__d)) {
static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
}
- template <bool _Dummy = true, class = _EnableIfDeleterConstructible<_BadRValRefType<_Dummy> > >
- _LIBCPP_HIDE_FROM_ABI unique_ptr(pointer __p, _BadRValRefType<_Dummy> __d) = delete;
+ template <bool _Dummy = true,
+ __enable_if_t<_Dummy && is_reference<deleter_type>::value &&
+ is_constructible<deleter_type, __libcpp_remove_reference_t<deleter_type>&&>::value,
+ int> = 0>
+ _LIBCPP_HIDE_FROM_ABI unique_ptr(pointer __p, __libcpp_remove_reference_t<deleter_type>&& __d) = delete;
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(unique_ptr&& __u) _NOEXCEPT
: __ptr_(__u.release()),
@@ -438,20 +408,9 @@ class _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI unique_ptr<_Tp[], _Dp> {
(is_same<pointer, element_type*>::value &&
is_convertible<_FromElem (*)[], element_type (*)[]>::value) > {};
- typedef __unique_ptr_deleter_sfinae<_Dp> _DeleterSFINAE;
-
- template <bool _Dummy>
- using _LValRefType _LIBCPP_NODEBUG = typename __dependent_type<_DeleterSFINAE, _Dummy>::__lval_ref_type;
-
- template <bool _Dummy>
- using _GoodRValRefType _LIBCPP_NODEBUG = typename __dependent_type<_DeleterSFINAE, _Dummy>::__good_rval_ref_type;
-
template <bool _Dummy>
- using _BadRValRefType _LIBCPP_NODEBUG = typename __dependent_type<_DeleterSFINAE, _Dummy>::__bad_rval_ref_type;
-
- template <bool _Dummy, class _Deleter = typename __dependent_type< __type_identity<deleter_type>, _Dummy>::type>
using _EnableIfDeleterDefaultConstructible _LIBCPP_NODEBUG =
- __enable_if_t<is_default_constructible<_Deleter>::value && !is_pointer<_Deleter>::value>;
+ __enable_if_t<_Dummy && is_default_constructible<deleter_type>::value && !is_pointer<deleter_type>::value>;
template <class _ArgType>
using _EnableIfDeleterConstructible _LIBCPP_NODEBUG = __enable_if_t<is_constructible<deleter_type, _ArgType>::value>;
@@ -495,42 +454,48 @@ class _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI unique_ptr<_Tp[], _Dp> {
__checker_(__size) {}
template <class _Pp,
- bool _Dummy = true,
- class = _EnableIfDeleterConstructible<_LValRefType<_Dummy> >,
- class = _EnableIfPointerConvertible<_Pp> >
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(_Pp __ptr, _LValRefType<_Dummy> __deleter) _NOEXCEPT
+ bool _Dummy = true,
+ __enable_if_t<_Dummy && is_constructible<deleter_type, const deleter_type&>::value, int> = 0,
+ class = _EnableIfPointerConvertible<_Pp> >
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(_Pp __ptr, const deleter_type& __deleter) _NOEXCEPT
: __ptr_(__ptr),
__deleter_(__deleter) {}
- template <bool _Dummy = true, class = _EnableIfDeleterConstructible<_LValRefType<_Dummy> > >
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(nullptr_t, _LValRefType<_Dummy> __deleter) _NOEXCEPT
+ template <bool _Dummy = true,
+ __enable_if_t<_Dummy && is_constructible<deleter_type, const deleter_type&>::value, int> = 0>
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(nullptr_t, const deleter_type& __deleter) _NOEXCEPT
: __ptr_(nullptr),
__deleter_(__deleter) {}
template <class _Pp,
- bool _Dummy = true,
- class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy> >,
- class = _EnableIfPointerConvertible<_Pp> >
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23
- unique_ptr(_Pp __ptr, _GoodRValRefType<_Dummy> __deleter) _NOEXCEPT
+ bool _Dummy = true,
+ __enable_if_t<_Dummy && !is_reference<deleter_type>::value &&
+ is_constructible<deleter_type, deleter_type&&>::value,
+ int> = 0,
+ class = _EnableIfPointerConvertible<_Pp> >
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(_Pp __ptr, deleter_type&& __deleter) _NOEXCEPT
: __ptr_(__ptr),
__deleter_(std::move(__deleter)) {
static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
}
- template <bool _Dummy = true, class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy> > >
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23
- unique_ptr(nullptr_t, _GoodRValRefType<_Dummy> __deleter) _NOEXCEPT
+ template <bool _Dummy = true,
+ __enable_if_t<_Dummy && !is_reference<deleter_type>::value &&
+ is_constructible<deleter_type, deleter_type&&>::value,
+ int> = 0>
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(nullptr_t, deleter_type&& __deleter) _NOEXCEPT
: __ptr_(nullptr),
__deleter_(std::move(__deleter)) {
static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
}
template <class _Pp,
- bool _Dummy = true,
- class = _EnableIfDeleterConstructible<_BadRValRefType<_Dummy> >,
- class = _EnableIfPointerConvertible<_Pp> >
- _LIBCPP_HIDE_FROM_ABI unique_ptr(_Pp __ptr, _BadRValRefType<_Dummy> __deleter) = delete;
+ bool _Dummy = true,
+ __enable_if_t<_Dummy && is_reference<deleter_type>::value &&
+ is_constructible<deleter_type, __libcpp_remove_reference_t<deleter_type>&&>::value,
+ int> = 0,
+ class = _EnableIfPointerConvertible<_Pp> >
+ _LIBCPP_HIDE_FROM_ABI unique_ptr(_Pp __ptr, __libcpp_remove_reference_t<deleter_type>&& __deleter) = delete;
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(unique_ptr&& __u) _NOEXCEPT
: __ptr_(__u.release()),
diff --git a/libcxx/include/__type_traits/dependent_type.h b/libcxx/include/__type_traits/dependent_type.h
deleted file mode 100644
index 354705c49c90e..0000000000000
--- a/libcxx/include/__type_traits/dependent_type.h
+++ /dev/null
@@ -1,25 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef _LIBCPP___TYPE_TRAITS_DEPENDENT_TYPE_H
-#define _LIBCPP___TYPE_TRAITS_DEPENDENT_TYPE_H
-
-#include <__config>
-
-#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
-# pragma GCC system_header
-#endif
-
-_LIBCPP_BEGIN_NAMESPACE_STD
-
-template <class _Tp, bool>
-struct __dependent_type : public _Tp {};
-
-_LIBCPP_END_NAMESPACE_STD
-
-#endif // _LIBCPP___TYPE_TRAITS_DEPENDENT_TYPE_H
diff --git a/libcxx/include/module.modulemap.in b/libcxx/include/module.modulemap.in
index 24a2fe761943a..144057597100f 100644
--- a/libcxx/include/module.modulemap.in
+++ b/libcxx/include/module.modulemap.in
@@ -84,7 +84,6 @@ module std_core [system] {
module copy_cvref { header "__type_traits/copy_cvref.h" }
module datasizeof { header "__type_traits/datasizeof.h" }
module decay { header "__type_traits/decay.h" }
- module dependent_type { header "__type_traits/dependent_type.h" }
module desugars_to { header "__type_traits/desugars_to.h" }
module detected_or { header "__type_traits/detected_or.h" }
module disjunction { header "__type_traits/disjunction.h" }
diff --git a/libcxx/include/variant b/libcxx/include/variant
index 8e958581a6b07..efcc54f101b87 100644
--- a/libcxx/include/variant
+++ b/libcxx/include/variant
@@ -235,7 +235,6 @@ namespace std {
# include <__type_traits/conditional.h>
# include <__type_traits/conjunction.h>
# include <__type_traits/decay.h>
-# include <__type_traits/dependent_type.h>
# include <__type_traits/enable_if.h>
# include <__type_traits/invoke.h>
# include <__type_traits/is_array.h>
@@ -1174,8 +1173,7 @@ public:
conditional_t<_And<__libcpp_is_trivially_relocatable<_Types>...>::value, variant, void>;
using __replaceable _LIBCPP_NODEBUG = conditional_t<_And<__is_replaceable<_Types>...>::value, variant, void>;
- template <bool _Dummy = true,
- enable_if_t<__dependent_type<is_default_constructible<__first_type>, _Dummy>::value, int> = 0>
+ template <bool _Dummy = true, enable_if_t<_Dummy && is_default_constructible<__first_type>::value, int> = 0>
_LIBCPP_HIDE_FROM_ABI constexpr variant() noexcept(is_nothrow_default_constructible_v<__first_type>)
: __impl_(in_place_index<0>) {}
@@ -1290,10 +1288,9 @@ public:
_LIBCPP_HIDE_FROM_ABI constexpr size_t index() const noexcept { return __impl_.index(); }
- template < bool _Dummy = true,
- enable_if_t< __all<(__dependent_type<is_move_constructible<_Types>, _Dummy>::value &&
- __dependent_type<is_swappable<_Types>, _Dummy>::value)...>::value,
- int> = 0>
+ template <
+ bool _Dummy = true,
+ enable_if_t<_Dummy && __all<(is_move_constructible_v<_Types> && is_swappable_v<_Types>)...>::value, int> = 0>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void swap(variant& __that) noexcept(
__all<(is_nothrow_move_constructible_v<_Types> && is_nothrow_swappable_v<_Types>)...>::value) {
__impl_.__swap(__that.__impl_);
More information about the libcxx-commits
mailing list