[llvm] 0de265c - [ADT] Consolidate assertSafeToReferenceAfterClear with "if constexpr" (NFC) (#161042)

via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 28 10:27:17 PDT 2025


Author: Kazu Hirata
Date: 2025-09-28T10:27:13-07:00
New Revision: 0de265c3e3beaa0ac0a2976b8c7905ce321987c1

URL: https://github.com/llvm/llvm-project/commit/0de265c3e3beaa0ac0a2976b8c7905ce321987c1
DIFF: https://github.com/llvm/llvm-project/commit/0de265c3e3beaa0ac0a2976b8c7905ce321987c1.diff

LOG: [ADT] Consolidate assertSafeToReferenceAfterClear with "if constexpr" (NFC) (#161042)

This patch consolidates two implementations of
assertSafeToReferenceAfterClear into a single template function.

Added: 
    

Modified: 
    llvm/include/llvm/ADT/SmallVector.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ADT/SmallVector.h b/llvm/include/llvm/ADT/SmallVector.h
index 36b324355ee10..77805f5c03c14 100644
--- a/llvm/include/llvm/ADT/SmallVector.h
+++ b/llvm/include/llvm/ADT/SmallVector.h
@@ -199,17 +199,18 @@ class SmallVectorTemplateCommon
   }
 
   /// Check whether any part of the range will be invalidated by clearing.
-  void assertSafeToReferenceAfterClear(const T *From, const T *To) {
-    if (From == To)
-      return;
-    this->assertSafeToReferenceAfterResize(From, 0);
-    this->assertSafeToReferenceAfterResize(To - 1, 0);
-  }
-  template <
-      class ItTy,
-      std::enable_if_t<!std::is_same<std::remove_const_t<ItTy>, T *>::value,
-                       bool> = false>
-  void assertSafeToReferenceAfterClear(ItTy, ItTy) {}
+  template <class ItTy>
+  void assertSafeToReferenceAfterClear(ItTy From, ItTy To) {
+    if constexpr (std::is_pointer_v<ItTy> &&
+                  std::is_same_v<
+                      std::remove_const_t<std::remove_pointer_t<ItTy>>,
+                      std::remove_const_t<T>>) {
+      if (From == To)
+        return;
+      this->assertSafeToReferenceAfterResize(From, 0);
+      this->assertSafeToReferenceAfterResize(To - 1, 0);
+    }
+  }
 
   /// Check whether any part of the range will be invalidated by growing.
   template <class ItTy> void assertSafeToAddRange(ItTy From, ItTy To) {


        


More information about the llvm-commits mailing list