[llvm] [ADT] Deprecate ArrayRef(std::nullopt) (PR #146011)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 26 23:00:46 PDT 2025
https://github.com/kazutakahirata updated https://github.com/llvm/llvm-project/pull/146011
>From 7e0b54147e08c9051cc13ec854e7db1e444453ed Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Mon, 22 Jan 2024 01:06:34 -0800
Subject: [PATCH 1/2] [ADT] Deprecate ArrayRef(std::nullopt)
Since the use of std::nullopt outside the context of std::optional is
kind of abuse and not intuitive to new comers, this patch deprecates
the constructor. All known uses within the LLVM codebase have been
migrated to other constructors.
---
llvm/include/llvm/ADT/ArrayRef.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/include/llvm/ADT/ArrayRef.h b/llvm/include/llvm/ADT/ArrayRef.h
index 892482d64e4a1..7a228d9915cde 100644
--- a/llvm/include/llvm/ADT/ArrayRef.h
+++ b/llvm/include/llvm/ADT/ArrayRef.h
@@ -67,7 +67,7 @@ namespace llvm {
/*implicit*/ ArrayRef() = default;
/// Construct an empty ArrayRef from std::nullopt.
- /*implicit*/ ArrayRef(std::nullopt_t) {}
+ /*implicit*/ [[deprecated]] ArrayRef(std::nullopt_t) {}
/// Construct an ArrayRef from a single element.
/*implicit*/ ArrayRef(const T &OneElt LLVM_LIFETIME_BOUND)
>From e83117be0fe851e6d876ac2f04746780c53fecd3 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Thu, 26 Jun 2025 22:47:10 -0700
Subject: [PATCH 2/2] Address a comment.
---
llvm/include/llvm/ADT/ArrayRef.h | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/llvm/include/llvm/ADT/ArrayRef.h b/llvm/include/llvm/ADT/ArrayRef.h
index 7a228d9915cde..cc3f23bd0e3d2 100644
--- a/llvm/include/llvm/ADT/ArrayRef.h
+++ b/llvm/include/llvm/ADT/ArrayRef.h
@@ -67,7 +67,8 @@ namespace llvm {
/*implicit*/ ArrayRef() = default;
/// Construct an empty ArrayRef from std::nullopt.
- /*implicit*/ [[deprecated]] ArrayRef(std::nullopt_t) {}
+ /*implicit*/ LLVM_DEPRECATED("Use {} or ArrayRef<T>() instead", "{}")
+ ArrayRef(std::nullopt_t) {}
/// Construct an ArrayRef from a single element.
/*implicit*/ ArrayRef(const T &OneElt LLVM_LIFETIME_BOUND)
More information about the llvm-commits
mailing list