[llvm] [ArrayRef] Add constructor from iterator_range<U*> (NFC). (PR #137796)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 30 03:38:55 PDT 2025


================
@@ -149,6 +149,13 @@ namespace llvm {
                  * = nullptr)
         : Data(Vec.data()), Length(Vec.size()) {}
 
+    /// Construct an ArrayRef<T> from iterator_range<U*>. This uses SFINAE
+    /// to ensure that this is only used for iterator ranges over plain pointer
+    /// iterators.
+    template <typename U, typename = std::enable_if_t<std::is_same_v<U *, T *>>>
----------------
fhahn wrote:

Unfortunately `is_same_v<U, remove_const_t<T>>` isn't sufficient to support pointer cases with different const-ness directly .

I updated the `is_convertible_v` check to add another level of indirection, which should forbids construction a ArrayRef for a non-pointer base from an iterator of derived*, the only case that was previously allowed. This is similar to how `std::vector` and `SmallVectorImpl` are handled above. Added a few more static asserts to the test

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


More information about the llvm-commits mailing list