From d727738369fb154d79b60a228e3829500a53b354 Mon Sep 17 00:00:00 2001 From: Justin Bogner Date: Sun, 16 Oct 2016 20:30:40 +0000 Subject: [PATCH] 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 --- llvm/include/llvm/ADT/ArrayRef.h | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/llvm/include/llvm/ADT/ArrayRef.h b/llvm/include/llvm/ADT/ArrayRef.h index 3efc09d..1c90478 100644 --- a/llvm/include/llvm/ADT/ArrayRef.h +++ b/llvm/include/llvm/ADT/ArrayRef.h @@ -29,7 +29,7 @@ namespace llvm { /// This is intended to be trivially copyable, so it should be passed by /// value. template - 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 slice(size_t N) const { assert(N <= size() && "Invalid specifier"); return ArrayRef(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 slice(size_t N, size_t M) const { assert(N+M <= size() && "Invalid specifier"); return ArrayRef(data()+N, M); } /// \brief Drop the first \p N elements of the array. - LLVM_ATTRIBUTE_UNUSED_RESULT ArrayRef 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 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 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 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 - class MutableArrayRef : public ArrayRef { + class LLVM_NODISCARD MutableArrayRef : public ArrayRef { 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 slice(size_t N) const { assert(N <= this->size() && "Invalid specifier"); return MutableArrayRef(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 slice(size_t N, size_t M) const { assert(N+M <= this->size() && "Invalid specifier"); return MutableArrayRef(data()+N, M); } /// \brief Drop the first \p N elements of the array. - LLVM_ATTRIBUTE_UNUSED_RESULT MutableArrayRef 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 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 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 take_back(size_t N = 1) const { if (N >= this->size()) return *this; -- 2.7.4