Skip to content

Commit 637c35a

Browse files
kazutakahiratarlavaee
authored andcommitted
[ADT] Remove a constructor (NFC) (llvm#146010)
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<uint8_t, 20>::size(). This patch adds an implicit cast operator to ArrayRef. Note that ASTFileSignature is defined as: struct ASTFileSignature : std::array<uint8_t, 20> { using BaseT = std::array<uint8_t, 20>; static constexpr size_t size = std::tuple_size<BaseT>::value; :
1 parent 369af41 commit 637c35a

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

clang/include/clang/Basic/Module.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ struct ASTFileSignature : std::array<uint8_t, 20> {
6464

6565
explicit operator bool() const { return *this != BaseT({{0}}); }
6666

67+
// Support implicit cast to ArrayRef. Note that ASTFileSignature::size
68+
// prevents implicit cast to ArrayRef because one of the implicit constructors
69+
// of ArrayRef requires access to BaseT::size.
70+
operator ArrayRef<uint8_t>() const { return ArrayRef<uint8_t>(data(), size); }
71+
6772
/// Returns the value truncated to the size of an uint64_t.
6873
uint64_t truncatedValue() const {
6974
uint64_t Value = 0;

llvm/include/llvm/ADT/ArrayRef.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,6 @@ namespace llvm {
9999
/*implicit*/ constexpr ArrayRef(const C &V)
100100
: Data(V.data()), Length(V.size()) {}
101101

102-
/// Construct an ArrayRef from a std::array
103-
template <size_t N>
104-
/*implicit*/ constexpr ArrayRef(const std::array<T, N> &Arr)
105-
: Data(Arr.data()), Length(N) {}
106-
107102
/// Construct an ArrayRef from a C array.
108103
template <size_t N>
109104
/*implicit*/ constexpr ArrayRef(const T (&Arr LLVM_LIFETIME_BOUND)[N])

0 commit comments

Comments
 (0)