ADT: Use LLVM_NODISCARD instead of LLVM_ATTRIBUTE_UNUSED_RESULT for ArrayRef

Instead of annotating (most of) the ArrayRef API, we can just annotate
the type directly. This is less code and it will warn in more cases.

llvm-svn: 284342
This commit is contained in:
Justin Bogner 2016-10-16 20:30:40 +00:00
parent 14994133bb
commit d727738369
1 changed files with 2 additions and 14 deletions
llvm/include/llvm/ADT

View File

@ -29,7 +29,7 @@ namespace llvm {
/// This is intended to be trivially copyable, so it should be passed by
/// value.
template<typename T>
class ArrayRef {
class LLVM_NODISCARD ArrayRef {
public:
typedef const T *iterator;
typedef const T *const_iterator;
@ -167,7 +167,6 @@ namespace llvm {
}
/// slice(n) - Chop off the first N elements of the array.
LLVM_ATTRIBUTE_UNUSED_RESULT
ArrayRef<T> slice(size_t N) const {
assert(N <= size() && "Invalid specifier");
return ArrayRef<T>(data()+N, size()-N);
@ -175,28 +174,24 @@ namespace llvm {
/// slice(n, m) - Chop off the first N elements of the array, and keep M
/// elements in the array.
LLVM_ATTRIBUTE_UNUSED_RESULT
ArrayRef<T> slice(size_t N, size_t M) const {
assert(N+M <= size() && "Invalid specifier");
return ArrayRef<T>(data()+N, M);
}
/// \brief Drop the first \p N elements of the array.
LLVM_ATTRIBUTE_UNUSED_RESULT
ArrayRef<T> drop_front(size_t N = 1) const {
assert(size() >= N && "Dropping more elements than exist");
return slice(N, size() - N);
}
/// \brief Drop the last \p N elements of the array.
LLVM_ATTRIBUTE_UNUSED_RESULT
ArrayRef<T> drop_back(size_t N = 1) const {
assert(size() >= N && "Dropping more elements than exist");
return slice(0, size() - N);
}
/// \brief Return a copy of *this with only the first \p N elements.
LLVM_ATTRIBUTE_UNUSED_RESULT
ArrayRef<T> take_front(size_t N = 1) const {
if (N >= size())
return *this;
@ -204,7 +199,6 @@ namespace llvm {
}
/// \brief Return a copy of *this with only the last \p N elements.
LLVM_ATTRIBUTE_UNUSED_RESULT
ArrayRef<T> take_back(size_t N = 1) const {
if (N >= size())
return *this;
@ -265,7 +259,7 @@ namespace llvm {
/// This is intended to be trivially copyable, so it should be passed by
/// value.
template<typename T>
class MutableArrayRef : public ArrayRef<T> {
class LLVM_NODISCARD MutableArrayRef : public ArrayRef<T> {
public:
typedef T *iterator;
@ -326,7 +320,6 @@ namespace llvm {
}
/// slice(n) - Chop off the first N elements of the array.
LLVM_ATTRIBUTE_UNUSED_RESULT
MutableArrayRef<T> slice(size_t N) const {
assert(N <= this->size() && "Invalid specifier");
return MutableArrayRef<T>(data()+N, this->size()-N);
@ -334,27 +327,23 @@ namespace llvm {
/// slice(n, m) - Chop off the first N elements of the array, and keep M
/// elements in the array.
LLVM_ATTRIBUTE_UNUSED_RESULT
MutableArrayRef<T> slice(size_t N, size_t M) const {
assert(N+M <= this->size() && "Invalid specifier");
return MutableArrayRef<T>(data()+N, M);
}
/// \brief Drop the first \p N elements of the array.
LLVM_ATTRIBUTE_UNUSED_RESULT
MutableArrayRef<T> drop_front(size_t N = 1) const {
assert(this->size() >= N && "Dropping more elements than exist");
return slice(N, this->size() - N);
}
LLVM_ATTRIBUTE_UNUSED_RESULT
MutableArrayRef<T> drop_back(size_t N = 1) const {
assert(this->size() >= N && "Dropping more elements than exist");
return slice(0, this->size() - N);
}
/// \brief Return a copy of *this with only the first \p N elements.
LLVM_ATTRIBUTE_UNUSED_RESULT
MutableArrayRef<T> take_front(size_t N = 1) const {
if (N >= this->size())
return *this;
@ -362,7 +351,6 @@ namespace llvm {
}
/// \brief Return a copy of *this with only the last \p N elements.
LLVM_ATTRIBUTE_UNUSED_RESULT
MutableArrayRef<T> take_back(size_t N = 1) const {
if (N >= this->size())
return *this;