-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[ADT] Remove a constructor (NFC) #146010
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ADT] Remove a constructor (NFC) #146010
Conversation
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; :
@llvm/pr-subscribers-clang-modules Author: Kazu Hirata (kazutakahirata) ChangesArrayRef now has a new constructor that takes a parameter whose type The only problem is that ASTFileSignature in the clang frontend does struct ASTFileSignature : std::array<uint8_t, 20> { Full diff: https://github.com/llvm/llvm-project/pull/146010.diff 2 Files Affected:
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<uint8_t, 20> {
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<uint8_t>() const { return ArrayRef<uint8_t>(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 <size_t N>
- /*implicit*/ constexpr ArrayRef(const std::array<T, N> &Arr)
- : Data(Arr.data()), Length(N) {}
-
/// Construct an ArrayRef from a C array.
template <size_t N>
/*implicit*/ constexpr ArrayRef(const T (&Arr LLVM_LIFETIME_BOUND)[N])
|
@llvm/pr-subscribers-clang Author: Kazu Hirata (kazutakahirata) ChangesArrayRef now has a new constructor that takes a parameter whose type The only problem is that ASTFileSignature in the clang frontend does struct ASTFileSignature : std::array<uint8_t, 20> { Full diff: https://github.com/llvm/llvm-project/pull/146010.diff 2 Files Affected:
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<uint8_t, 20> {
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<uint8_t>() const { return ArrayRef<uint8_t>(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 <size_t N>
- /*implicit*/ constexpr ArrayRef(const std::array<T, N> &Arr)
- : Data(Arr.data()), Length(N) {}
-
/// Construct an ArrayRef from a C array.
template <size_t N>
/*implicit*/ constexpr ArrayRef(const T (&Arr LLVM_LIFETIME_BOUND)[N])
|
@llvm/pr-subscribers-llvm-adt Author: Kazu Hirata (kazutakahirata) ChangesArrayRef now has a new constructor that takes a parameter whose type The only problem is that ASTFileSignature in the clang frontend does struct ASTFileSignature : std::array<uint8_t, 20> { Full diff: https://github.com/llvm/llvm-project/pull/146010.diff 2 Files Affected:
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<uint8_t, 20> {
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<uint8_t>() const { return ArrayRef<uint8_t>(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 <size_t N>
- /*implicit*/ constexpr ArrayRef(const std::array<T, N> &Arr)
- : Data(Arr.data()), Length(N) {}
-
/// Construct an ArrayRef from a C array.
template <size_t N>
/*implicit*/ constexpr ArrayRef(const T (&Arr LLVM_LIFETIME_BOUND)[N])
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same constructor also exists on MutableArrayRef
@d0k I'll get to that in a separate PR. Thanks for the review! |
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/153/builds/36246 Here is the relevant piece of the build log for the reference
|
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::value;
: