[ArrayRef] Bring MutableArrayRef's constructor in line with ArrayRef

This time when the argument has a data member returning a mutable
pointer.
This commit is contained in:
Benjamin Kramer
2025-06-26 11:12:05 +02:00
parent d144eb1d8c
commit e8f85cf51f
2 changed files with 20 additions and 7 deletions

View File

@@ -320,13 +320,16 @@ namespace llvm {
/// Construct a MutableArrayRef from a range.
MutableArrayRef(T *begin, T *end) : ArrayRef<T>(begin, end) {}
/// Construct a MutableArrayRef from a SmallVector.
/*implicit*/ MutableArrayRef(SmallVectorImpl<T> &Vec)
: ArrayRef<T>(Vec) {}
/// Construct a MutableArrayRef from a std::vector.
/*implicit*/ MutableArrayRef(std::vector<T> &Vec)
: ArrayRef<T>(Vec) {}
/// Construct a MutableArrayRef from a type that has a data() method that
/// returns a pointer convertible to T *.
template <typename C,
typename = std::enable_if_t<
std::conjunction_v<
std::is_convertible<
decltype(std::declval<C &>().data()) *, T *const *>,
std::is_integral<decltype(std::declval<C &>().size())>>,
void>>
/*implicit*/ constexpr MutableArrayRef(const C &V) : ArrayRef<T>(V) {}
/// Construct a MutableArrayRef from a std::array
template <size_t N>

View File

@@ -421,6 +421,16 @@ static_assert(std::is_constructible_v<ArrayRef<int>, std::span<int>>,
"should be able to construct ArrayRef from mutable std::span");
static_assert(!std::is_constructible_v<std::span<int>, ArrayRef<int>>,
"cannot construct mutable std::span from ArrayRef");
static_assert(
!std::is_constructible_v<MutableArrayRef<int>, std::span<const int>>,
"cannot construct MutableArrayRef from const std::span");
static_assert(
std::is_constructible_v<std::span<const int>, MutableArrayRef<int>>,
"should be able to construct const std::span from MutableArrayRef");
static_assert(
std::is_constructible_v<MutableArrayRef<int>, std::span<int>>,
"should be able to construct MutableArrayRef from mutable std::span");
#endif
} // end anonymous namespace