Skip to content

Commit e168691

Browse files
[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<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 96ec1c2 commit e168691

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
@@ -98,11 +98,6 @@ namespace llvm {
9898
/*implicit*/ constexpr ArrayRef(const C &V)
9999
: Data(V.data()), Length(V.size()) {}
100100

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

0 commit comments

Comments
 (0)