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

Zachary Turner via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 22 11:58:42 PST 2016


This is another example where I think LLVM_NODISCARD is inappropriate.
Just because a function returns an ArrayRef doesn't mean I need to check
its value.  I have not undone this change yet since it was not blocking
anything, but I found this after the fact.  I think we should go back to
putting it on the individual members here.

On Sun, Oct 16, 2016 at 1:39 PM Justin Bogner via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

> 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;
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161122/6d0019e3/attachment.html>


More information about the llvm-commits mailing list