[libcxx-commits] [libcxx] 484e64f - [libc++] Use __is_convertible built-in when available

Roland McGrath via libcxx-commits libcxx-commits at lists.llvm.org
Thu Apr 27 14:23:52 PDT 2023


Author: Roland McGrath
Date: 2023-04-27T14:23:43-07:00
New Revision: 484e64f7e7b2c0494d7b2dbfdd528bcd707ee652

URL: https://github.com/llvm/llvm-project/commit/484e64f7e7b2c0494d7b2dbfdd528bcd707ee652
DIFF: https://github.com/llvm/llvm-project/commit/484e64f7e7b2c0494d7b2dbfdd528bcd707ee652.diff

LOG: [libc++] Use __is_convertible built-in when available

https://github.com/llvm/llvm-project/issues/62396 reports that
GCC 13 barfs on parsing <type_traits> because of the declarations
of `struct __is_convertible`.  In GCC 13, `__is_convertible` is a
built-in, but `__is_convertible_to` is not.  Clang has both, so
using either should be fine.

Reviewed By: #libc, philnik

Differential Revision: https://reviews.llvm.org/D149313

Added: 
    

Modified: 
    libcxx/include/__type_traits/is_convertible.h

Removed: 
    


################################################################################
diff  --git a/libcxx/include/__type_traits/is_convertible.h b/libcxx/include/__type_traits/is_convertible.h
index 873a64b5a486c..749d6fd47af9c 100644
--- a/libcxx/include/__type_traits/is_convertible.h
+++ b/libcxx/include/__type_traits/is_convertible.h
@@ -24,11 +24,18 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-#if __has_builtin(__is_convertible_to) && !defined(_LIBCPP_USE_IS_CONVERTIBLE_FALLBACK)
+#if __has_builtin(__is_convertible) && !defined(_LIBCPP_USE_IS_CONVERTIBLE_FALLBACK)
+
+template <class _T1, class _T2>
+struct _LIBCPP_TEMPLATE_VIS is_convertible : public integral_constant<bool, __is_convertible(_T1, _T2)> {};
+
+#elif __has_builtin(__is_convertible_to) && !defined(_LIBCPP_USE_IS_CONVERTIBLE_FALLBACK)
 
 template <class _T1, class _T2> struct _LIBCPP_TEMPLATE_VIS is_convertible
     : public integral_constant<bool, __is_convertible_to(_T1, _T2)> {};
 
+// TODO: Remove this fallback when GCC < 13 support is no longer required.
+// GCC 13 has the __is_convertible built-in.
 #else  // __has_builtin(__is_convertible_to) && !defined(_LIBCPP_USE_IS_CONVERTIBLE_FALLBACK)
 
 namespace __is_convertible_imp


        


More information about the libcxx-commits mailing list