[llvm] Remove misleading is_const check in MutableArrayRef constructor (PR #181758)

Eric Feng via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 16 16:31:17 PST 2026


https://github.com/efric updated https://github.com/llvm/llvm-project/pull/181758

>From 375171f3907765e8ed70cf6e3fc18dcb0f29c2cb Mon Sep 17 00:00:00 2001
From: Eric Feng <Eric.Feng at amd.com>
Date: Mon, 16 Feb 2026 15:47:24 -0800
Subject: [PATCH 1/2] remove unnecessary const

Signed-off-by: Eric Feng <Eric.Feng at amd.com>
---
 llvm/include/llvm/ADT/ArrayRef.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/llvm/include/llvm/ADT/ArrayRef.h b/llvm/include/llvm/ADT/ArrayRef.h
index 84c083cb1e666..716e2b0e3bcf3 100644
--- a/llvm/include/llvm/ADT/ArrayRef.h
+++ b/llvm/include/llvm/ADT/ArrayRef.h
@@ -327,7 +327,6 @@ 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())>>,

>From 83f80a72cf79f465518560f8c175e917bcef3eb2 Mon Sep 17 00:00:00 2001
From: Eric Feng <Eric.Feng at amd.com>
Date: Mon, 16 Feb 2026 16:28:50 -0800
Subject: [PATCH 2/2] add unit test

Signed-off-by: Eric Feng <Eric.Feng at amd.com>
---
 llvm/unittests/ADT/ArrayRefTest.cpp | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/llvm/unittests/ADT/ArrayRefTest.cpp b/llvm/unittests/ADT/ArrayRefTest.cpp
index 23677589d5367..3254fb1291e00 100644
--- a/llvm/unittests/ADT/ArrayRefTest.cpp
+++ b/llvm/unittests/ADT/ArrayRefTest.cpp
@@ -491,6 +491,10 @@ static_assert(
 static_assert(
     std::is_constructible_v<MutableArrayRef<int>, std::span<int>>,
     "should be able to construct MutableArrayRef from mutable std::span");
+static_assert(
+    std::is_constructible_v<MutableArrayRef<int>, const std::span<int>>,
+    "should be able to construct MutableArrayRef from const std::span with "
+    "mutable elements");
 #endif
 
 } // end anonymous namespace



More information about the llvm-commits mailing list