[llvm] Add const check (PR #181190)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 12 09:24:16 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-adt
Author: Dmitrii Makarenko (Devjiu)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/181190.diff
2 Files Affected:
- (modified) llvm/include/llvm/ADT/ArrayRef.h (+2-1)
- (modified) llvm/unittests/ADT/ArrayRefTest.cpp (+4)
``````````diff
diff --git a/llvm/include/llvm/ADT/ArrayRef.h b/llvm/include/llvm/ADT/ArrayRef.h
index 00b5534469d65..84c083cb1e666 100644
--- a/llvm/include/llvm/ADT/ArrayRef.h
+++ b/llvm/include/llvm/ADT/ArrayRef.h
@@ -327,11 +327,12 @@ namespace llvm {
template <typename C,
typename = std::enable_if_t<
std::conjunction_v<
+ std::negation<std::is_const<C>>,
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) {}
+ /*implicit*/ constexpr MutableArrayRef(C &V) : ArrayRef<T>(V) {}
/// Construct a MutableArrayRef from a C array.
template <size_t N>
diff --git a/llvm/unittests/ADT/ArrayRefTest.cpp b/llvm/unittests/ADT/ArrayRefTest.cpp
index b1a86f0214b74..23677589d5367 100644
--- a/llvm/unittests/ADT/ArrayRefTest.cpp
+++ b/llvm/unittests/ADT/ArrayRefTest.cpp
@@ -468,6 +468,10 @@ TEST(ArrayRefTest, MutableArrayRefDeductionGuides) {
}
}
+static_assert(
+ !std::is_constructible_v<MutableArrayRef<int>, const SmallVector<int>>,
+ "cannot construct MutableArrayRef from const std::SmallVector<int>");
+
#ifdef __cpp_lib_span
static_assert(std::is_constructible_v<ArrayRef<int>, std::span<const int>>,
"should be able to construct ArrayRef from const std::span");
``````````
</details>
https://github.com/llvm/llvm-project/pull/181190
More information about the llvm-commits
mailing list