[libcxx-commits] [libcxx] [libc++] Simplify is_array and is_nothrow_convertible (PR #134491)

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Sat Apr 5 03:27:33 PDT 2025


https://github.com/philnik777 created https://github.com/llvm/llvm-project/pull/134491

The type traits builtins are available in all supported compilers now, so we can use them unconditionally.


>From 12c303467eccde0919c28a63de3980b8e138bd28 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser <nikolasklauser at berlin.de>
Date: Sat, 5 Apr 2025 12:26:31 +0200
Subject: [PATCH] [libc++] Simplify is_array and is_nothrow_convertible

---
 libcxx/include/CMakeLists.txt                 |  1 -
 libcxx/include/__type_traits/is_array.h       | 24 +------
 libcxx/include/__type_traits/is_convertible.h | 10 +++
 .../__type_traits/is_nothrow_convertible.h    | 62 -------------------
 libcxx/include/module.modulemap               |  4 --
 libcxx/include/type_traits                    |  1 -
 6 files changed, 12 insertions(+), 90 deletions(-)
 delete mode 100644 libcxx/include/__type_traits/is_nothrow_convertible.h

diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index a021b9bb44d67..4ccc08e21a539 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -829,7 +829,6 @@ set(files
   __type_traits/is_member_pointer.h
   __type_traits/is_nothrow_assignable.h
   __type_traits/is_nothrow_constructible.h
-  __type_traits/is_nothrow_convertible.h
   __type_traits/is_nothrow_destructible.h
   __type_traits/is_null_pointer.h
   __type_traits/is_object.h
diff --git a/libcxx/include/__type_traits/is_array.h b/libcxx/include/__type_traits/is_array.h
index 0bde0aa970f88..6b943525c518e 100644
--- a/libcxx/include/__type_traits/is_array.h
+++ b/libcxx/include/__type_traits/is_array.h
@@ -10,7 +10,6 @@
 #define _LIBCPP___TYPE_TRAITS_IS_ARRAY_H
 
 #include <__config>
-#include <__cstddef/size_t.h>
 #include <__type_traits/integral_constant.h>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -19,32 +18,13 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-#if __has_builtin(__is_array) &&                                                                                       \
-    (!defined(_LIBCPP_COMPILER_CLANG_BASED) || (defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER >= 1900))
-
 template <class _Tp>
 struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_array : _BoolConstant<__is_array(_Tp)> {};
 
-#  if _LIBCPP_STD_VER >= 17
+#if _LIBCPP_STD_VER >= 17
 template <class _Tp>
 _LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_array_v = __is_array(_Tp);
-#  endif
-
-#else
-
-template <class _Tp>
-struct _LIBCPP_TEMPLATE_VIS is_array : public false_type {};
-template <class _Tp>
-struct _LIBCPP_TEMPLATE_VIS is_array<_Tp[]> : public true_type {};
-template <class _Tp, size_t _Np>
-struct _LIBCPP_TEMPLATE_VIS is_array<_Tp[_Np]> : public true_type {};
-
-#  if _LIBCPP_STD_VER >= 17
-template <class _Tp>
-inline constexpr bool is_array_v = is_array<_Tp>::value;
-#  endif
-
-#endif // __has_builtin(__is_array)
+#endif
 
 _LIBCPP_END_NAMESPACE_STD
 
diff --git a/libcxx/include/__type_traits/is_convertible.h b/libcxx/include/__type_traits/is_convertible.h
index 61f6cf644124e..4e735f911c9a4 100644
--- a/libcxx/include/__type_traits/is_convertible.h
+++ b/libcxx/include/__type_traits/is_convertible.h
@@ -27,6 +27,16 @@ template <class _From, class _To>
 _LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_convertible_v = __is_convertible(_From, _To);
 #endif
 
+#if _LIBCPP_STD_VER >= 20
+
+template <class _Tp, class _Up>
+struct _LIBCPP_NO_SPECIALIZATIONS is_nothrow_convertible : bool_constant<__is_nothrow_convertible(_Tp, _Up)> {};
+
+template <class _Tp, class _Up>
+_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_nothrow_convertible_v = __is_nothrow_convertible(_Tp, _Up);
+
+#endif // _LIBCPP_STD_VER >= 20
+
 _LIBCPP_END_NAMESPACE_STD
 
 #endif // _LIBCPP___TYPE_TRAITS_IS_CONVERTIBLE_H
diff --git a/libcxx/include/__type_traits/is_nothrow_convertible.h b/libcxx/include/__type_traits/is_nothrow_convertible.h
deleted file mode 100644
index f114619296437..0000000000000
--- a/libcxx/include/__type_traits/is_nothrow_convertible.h
+++ /dev/null
@@ -1,62 +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_IS_NOTHROW_CONVERTIBLE_H
-#define _LIBCPP___TYPE_TRAITS_IS_NOTHROW_CONVERTIBLE_H
-
-#include <__config>
-#include <__type_traits/conjunction.h>
-#include <__type_traits/disjunction.h>
-#include <__type_traits/integral_constant.h>
-#include <__type_traits/is_convertible.h>
-#include <__type_traits/is_void.h>
-#include <__type_traits/lazy.h>
-#include <__utility/declval.h>
-
-#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
-#  pragma GCC system_header
-#endif
-
-_LIBCPP_BEGIN_NAMESPACE_STD
-
-#if _LIBCPP_STD_VER >= 20
-
-#  if __has_builtin(__is_nothrow_convertible)
-
-template <class _Tp, class _Up>
-struct _LIBCPP_NO_SPECIALIZATIONS is_nothrow_convertible : bool_constant<__is_nothrow_convertible(_Tp, _Up)> {};
-
-template <class _Tp, class _Up>
-_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_nothrow_convertible_v = __is_nothrow_convertible(_Tp, _Up);
-
-#  else // __has_builtin(__is_nothrow_convertible)
-
-template <typename _Tp>
-void __test_noexcept(_Tp) noexcept;
-
-template <typename _Fm, typename _To>
-bool_constant<noexcept(std::__test_noexcept<_To>(std::declval<_Fm>()))> __is_nothrow_convertible_test();
-
-template <typename _Fm, typename _To>
-struct __is_nothrow_convertible_helper : decltype(std::__is_nothrow_convertible_test<_Fm, _To>()) {};
-
-template <typename _Fm, typename _To>
-struct is_nothrow_convertible
-    : _Or<_And<is_void<_To>, is_void<_Fm>>,
-          _Lazy<_And, is_convertible<_Fm, _To>, __is_nothrow_convertible_helper<_Fm, _To> > >::type {};
-
-template <typename _Fm, typename _To>
-inline constexpr bool is_nothrow_convertible_v = is_nothrow_convertible<_Fm, _To>::value;
-
-#  endif // __has_builtin(__is_nothrow_convertible)
-
-#endif // _LIBCPP_STD_VER >= 20
-
-_LIBCPP_END_NAMESPACE_STD
-
-#endif // _LIBCPP___TYPE_TRAITS_IS_NOTHROW_CONVERTIBLE_H
diff --git a/libcxx/include/module.modulemap b/libcxx/include/module.modulemap
index 0ce42fc4d3633..ee7f525c0607d 100644
--- a/libcxx/include/module.modulemap
+++ b/libcxx/include/module.modulemap
@@ -231,10 +231,6 @@ module std_core [system] {
       header "__type_traits/is_nothrow_constructible.h"
       export std_core.type_traits.integral_constant
     }
-    module is_nothrow_convertible {
-      header "__type_traits/is_nothrow_convertible.h"
-      export std_core.type_traits.integral_constant
-    }
     module is_nothrow_destructible {
       header "__type_traits/is_nothrow_destructible.h"
       export std_core.type_traits.integral_constant
diff --git a/libcxx/include/type_traits b/libcxx/include/type_traits
index a03a60917cd54..cdf0b2d0d3024 100644
--- a/libcxx/include/type_traits
+++ b/libcxx/include/type_traits
@@ -549,7 +549,6 @@ namespace std
 #    include <__type_traits/common_reference.h>
 #    include <__type_traits/is_bounded_array.h>
 #    include <__type_traits/is_constant_evaluated.h>
-#    include <__type_traits/is_nothrow_convertible.h>
 #    include <__type_traits/is_unbounded_array.h>
 #    include <__type_traits/type_identity.h>
 #    include <__type_traits/unwrap_ref.h>



More information about the libcxx-commits mailing list