[llvm] r284342 - ADT: Use LLVM_NODISCARD instead of LLVM_ATTRIBUTE_UNUSED_RESULT for ArrayRef

Justin Bogner via llvm-commits llvm-commits at lists.llvm.org
Sun Oct 16 13:30:40 PDT 2016


Author: bogner
Date: Sun Oct 16 15:30:40 2016
New Revision: 284342

URL: http://llvm.org/viewvc/llvm-project?rev=284342&view=rev
Log:
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.

Modified:
    llvm/trunk/include/llvm/ADT/ArrayRef.h

Modified: llvm/trunk/include/llvm/ADT/ArrayRef.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/ArrayRef.h?rev=284342&r1=284341&r2=284342&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/ArrayRef.h (original)
+++ llvm/trunk/include/llvm/ADT/ArrayRef.h Sun Oct 16 15:30:40 2016
@@ -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;




More information about the llvm-commits mailing list