diff --git a/llvm/include/llvm/ADT/ArrayRef.h b/llvm/include/llvm/ADT/ArrayRef.h index ddd2c7ce68c8..892482d64e4a 100644 --- a/llvm/include/llvm/ADT/ArrayRef.h +++ b/llvm/include/llvm/ADT/ArrayRef.h @@ -320,13 +320,16 @@ namespace llvm { /// Construct a MutableArrayRef from a range. MutableArrayRef(T *begin, T *end) : ArrayRef(begin, end) {} - /// Construct a MutableArrayRef from a SmallVector. - /*implicit*/ MutableArrayRef(SmallVectorImpl &Vec) - : ArrayRef(Vec) {} - - /// Construct a MutableArrayRef from a std::vector. - /*implicit*/ MutableArrayRef(std::vector &Vec) - : ArrayRef(Vec) {} + /// Construct a MutableArrayRef from a type that has a data() method that + /// returns a pointer convertible to T *. + template ().data()) *, T *const *>, + std::is_integral().size())>>, + void>> + /*implicit*/ constexpr MutableArrayRef(const C &V) : ArrayRef(V) {} /// Construct a MutableArrayRef from a std::array template diff --git a/llvm/unittests/ADT/ArrayRefTest.cpp b/llvm/unittests/ADT/ArrayRefTest.cpp index 3858d9064f9c..985db1625454 100644 --- a/llvm/unittests/ADT/ArrayRefTest.cpp +++ b/llvm/unittests/ADT/ArrayRefTest.cpp @@ -421,6 +421,16 @@ static_assert(std::is_constructible_v, std::span>, "should be able to construct ArrayRef from mutable std::span"); static_assert(!std::is_constructible_v, ArrayRef>, "cannot construct mutable std::span from ArrayRef"); + +static_assert( + !std::is_constructible_v, std::span>, + "cannot construct MutableArrayRef from const std::span"); +static_assert( + std::is_constructible_v, MutableArrayRef>, + "should be able to construct const std::span from MutableArrayRef"); +static_assert( + std::is_constructible_v, std::span>, + "should be able to construct MutableArrayRef from mutable std::span"); #endif } // end anonymous namespace