[libcxx-commits] [libcxx] [libc++] Assume that __array_rank is provided by the compiler (PR #202511)

via libcxx-commits libcxx-commits at lists.llvm.org
Wed Jun 10 01:16:09 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libcxx

Author: Nikolas Klauser (philnik777)

<details>
<summary>Changes</summary>

All compilers we support have `__array_rank`, so we can remove the preprocessor branch for supporting compilers which don't provide it.


---
Full diff: https://github.com/llvm/llvm-project/pull/202511.diff


1 Files Affected:

- (modified) libcxx/include/__type_traits/rank.h (+1-21) 


``````````diff
diff --git a/libcxx/include/__type_traits/rank.h b/libcxx/include/__type_traits/rank.h
index 5196b62949fa2..2a3f038a3f844 100644
--- a/libcxx/include/__type_traits/rank.h
+++ b/libcxx/include/__type_traits/rank.h
@@ -19,32 +19,12 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-#if __has_builtin(__array_rank) && !defined(_LIBCPP_COMPILER_CLANG_BASED) ||                                           \
-    (defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER >= 2001)
-
 template <class _Tp>
 struct _LIBCPP_NO_SPECIALIZATIONS rank : integral_constant<size_t, __array_rank(_Tp)> {};
 
-#else
-
-template <class _Tp>
-struct _LIBCPP_NO_SPECIALIZATIONS rank : public integral_constant<size_t, 0> {};
-
-_LIBCPP_DIAGNOSTIC_PUSH
-#  if __has_warning("-Winvalid-specialization")
-_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Winvalid-specialization")
-#  endif
-template <class _Tp>
-struct rank<_Tp[]> : public integral_constant<size_t, rank<_Tp>::value + 1> {};
-template <class _Tp, size_t _Np>
-struct rank<_Tp[_Np]> : public integral_constant<size_t, rank<_Tp>::value + 1> {};
-_LIBCPP_DIAGNOSTIC_POP
-
-#endif // __has_builtin(__array_rank)
-
 #if _LIBCPP_STD_VER >= 17
 template <class _Tp>
-_LIBCPP_NO_SPECIALIZATIONS inline constexpr size_t rank_v = rank<_Tp>::value;
+_LIBCPP_NO_SPECIALIZATIONS inline constexpr size_t rank_v = __array_rank(_Tp);
 #endif
 
 _LIBCPP_END_NAMESPACE_STD

``````````

</details>


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


More information about the libcxx-commits mailing list