From dfe604bb0570eff63030afb94f5dd0c9dae6247a Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Thu, 4 Sep 2025 21:31:45 -0700 Subject: [PATCH] [Support] Modernize PointerLikeTypeTraits with llvm::is_detected (NFC) This patch consolidates four separate template structs into a single IsPointerLike struct. A helper alias: using check_IsPointerLike = ...; encapsulates the logic to determine a type has pointer-like traits. --- .../llvm/Support/PointerLikeTypeTraits.h | 23 ++++++------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/llvm/include/llvm/Support/PointerLikeTypeTraits.h b/llvm/include/llvm/Support/PointerLikeTypeTraits.h index 1b15f930bd87d..f2e2eef487c61 100644 --- a/llvm/include/llvm/Support/PointerLikeTypeTraits.h +++ b/llvm/include/llvm/Support/PointerLikeTypeTraits.h @@ -14,6 +14,7 @@ #ifndef LLVM_SUPPORT_POINTERLIKETYPETRAITS_H #define LLVM_SUPPORT_POINTERLIKETYPETRAITS_H +#include "llvm/ADT/STLExtras.h" #include "llvm/Support/DataTypes.h" #include #include @@ -31,25 +32,15 @@ struct ConstantLog2 : std::integral_constant::value + 1> {}; template <> struct ConstantLog2<1> : std::integral_constant {}; -// Provide a trait to check if T is pointer-like. -template struct HasPointerLikeTypeTraits { - static const bool value = false; -}; - // sizeof(T) is valid only for a complete T. template -struct HasPointerLikeTypeTraits< - T, decltype((sizeof(PointerLikeTypeTraits) + sizeof(T)), void())> { - static const bool value = true; -}; +using check_IsPointerLike = + std::void_t)), + decltype(sizeof(T))>; -template struct IsPointerLike { - static const bool value = HasPointerLikeTypeTraits::value; -}; - -template struct IsPointerLike { - static const bool value = true; -}; +// Provide a trait to check if T is pointer-like. +template +struct IsPointerLike : is_detected {}; } // namespace detail // Provide PointerLikeTypeTraits for non-cvr pointers.