Skip to content

Conversation

kazutakahirata
Copy link
Contributor

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

… (NFC)

This patch consolidates two implementations of
assertSafeToReferenceAfterClear into a single template function.
@llvmbot
Copy link
Member

llvmbot commented Sep 28, 2025

@llvm/pr-subscribers-llvm-adt

Author: Kazu Hirata (kazutakahirata)

Changes

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


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

1 Files Affected:

  • (modified) llvm/include/llvm/ADT/SmallVector.h (+12-11)
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) {

@kazutakahirata kazutakahirata merged commit 0de265c into llvm:main Sep 28, 2025
11 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_20250927_ADT_SmallVector_assertSafeToReferenceAfterClear branch September 28, 2025 17:40
mahesh-attarde pushed a commit to mahesh-attarde/llvm-project that referenced this pull request Oct 3, 2025
… (NFC) (llvm#161042)

This patch consolidates two implementations of
assertSafeToReferenceAfterClear into a single template function.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants