Skip to content

Conversation

kazutakahirata
Copy link
Contributor

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.

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.
@llvmbot
Copy link
Member

llvmbot commented Sep 5, 2025

@llvm/pr-subscribers-llvm-support

Author: Kazu Hirata (kazutakahirata)

Changes

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.


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

1 Files Affected:

  • (modified) llvm/include/llvm/Support/PointerLikeTypeTraits.h (+7-16)
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 <cassert>
 #include <type_traits>
@@ -31,25 +32,15 @@ struct ConstantLog2
     : std::integral_constant<size_t, ConstantLog2<N / 2>::value + 1> {};
 template <> struct ConstantLog2<1> : std::integral_constant<size_t, 0> {};
 
-// Provide a trait to check if T is pointer-like.
-template <typename T, typename U = void> struct HasPointerLikeTypeTraits {
-  static const bool value = false;
-};
-
 // sizeof(T) is valid only for a complete T.
 template <typename T>
-struct HasPointerLikeTypeTraits<
-    T, decltype((sizeof(PointerLikeTypeTraits<T>) + sizeof(T)), void())> {
-  static const bool value = true;
-};
+using check_IsPointerLike =
+    std::void_t<decltype(sizeof(PointerLikeTypeTraits<T>)),
+                decltype(sizeof(T))>;
 
-template <typename T> struct IsPointerLike {
-  static const bool value = HasPointerLikeTypeTraits<T>::value;
-};
-
-template <typename T> struct IsPointerLike<T *> {
-  static const bool value = true;
-};
+// Provide a trait to check if T is pointer-like.
+template <typename T>
+struct IsPointerLike : is_detected<check_IsPointerLike, T> {};
 } // namespace detail
 
 // Provide PointerLikeTypeTraits for non-cvr pointers.

@kazutakahirata
Copy link
Contributor Author

Closing.

This is failing on Windows due to the way I handle the pointer of an incomplete type - Incomplete *. I could fix this, but that doesn't really result in simplification or line count reduction.

@kazutakahirata kazutakahirata deleted the cleanup_20250904_Support_PointerLike_HasPointerLikeTypeTraits branch September 5, 2025 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants