From e168691e87830e77ca6498cdc7b5abf24934eec1 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Thu, 26 Jun 2025 13:26:41 -0700 Subject: [PATCH] [ADT] Remove a constructor (NFC) ArrayRef now has a new constructor that takes a parameter whose type has data() and size() methods. Since the new constructor subsumes another constructor that takes std::array, this patch removes that constructor. Note that std::array also comes with data() and size() methods. The only problem is that ASTFileSignature in the clang frontend does not work with the new ArrayRef constructor because it overrides size, blocking access to std::array::size(). This patch adds an implicit cast operator to ArrayRef. Note that ASTFileSignature is defined as: struct ASTFileSignature : std::array { using BaseT = std::array; static constexpr size_t size = std::tuple_size::value; : --- clang/include/clang/Basic/Module.h | 5 +++++ llvm/include/llvm/ADT/ArrayRef.h | 5 ----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/clang/include/clang/Basic/Module.h b/clang/include/clang/Basic/Module.h index 3d035f0a5f787..69a1de6f79b35 100644 --- a/clang/include/clang/Basic/Module.h +++ b/clang/include/clang/Basic/Module.h @@ -64,6 +64,11 @@ struct ASTFileSignature : std::array { explicit operator bool() const { return *this != BaseT({{0}}); } + // Support implicit cast to ArrayRef. Note that ASTFileSignature::size + // prevents implicit cast to ArrayRef because one of the implicit constructors + // of ArrayRef requires access to BaseT::size. + operator ArrayRef() const { return ArrayRef(data(), size); } + /// Returns the value truncated to the size of an uint64_t. uint64_t truncatedValue() const { uint64_t Value = 0; diff --git a/llvm/include/llvm/ADT/ArrayRef.h b/llvm/include/llvm/ADT/ArrayRef.h index 892482d64e4a1..268510b803ea0 100644 --- a/llvm/include/llvm/ADT/ArrayRef.h +++ b/llvm/include/llvm/ADT/ArrayRef.h @@ -98,11 +98,6 @@ namespace llvm { /*implicit*/ constexpr ArrayRef(const C &V) : Data(V.data()), Length(V.size()) {} - /// Construct an ArrayRef from a std::array - template - /*implicit*/ constexpr ArrayRef(const std::array &Arr) - : Data(Arr.data()), Length(N) {} - /// Construct an ArrayRef from a C array. template /*implicit*/ constexpr ArrayRef(const T (&Arr LLVM_LIFETIME_BOUND)[N])