Bug 1201271 - Warn about unused results for more methods of nsTArray. r=froydnj
☠☠ backed out by f85819521302 ☠ ☠
authorAndrew McCreight <continuation@gmail.com>
Wed, 09 Sep 2015 15:39:10 -0700
changeset 261665 f5b2a11c64c95baff08c224478ed81f7da727fd6
parent 261664 f1fab424b6e06dbd9fd8751103d5a089d973c0f2
child 261666 f8581952130268f9b58570ea096b74ed0ac76d45
push id29352
push userphilringnalda@gmail.com
push dateThu, 10 Sep 2015 22:22:24 +0000
treeherdermozilla-central@c0abc2a6e11f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1201271
milestone43.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1201271 - Warn about unused results for more methods of nsTArray. r=froydnj This leaves alone the AppendElement methods.
dom/media/webaudio/AnalyserNode.cpp
mfbt/Assertions.h
storage/mozStorageBindingParams.cpp
toolkit/components/places/History.cpp
xpcom/glue/nsTArray.h
xpcom/tests/TestTArray.cpp
--- a/dom/media/webaudio/AnalyserNode.cpp
+++ b/dom/media/webaudio/AnalyserNode.cpp
@@ -88,17 +88,17 @@ AnalyserNode::AnalyserNode(AudioContext*
 {
   mStream = AudioNodeStream::Create(aContext->Graph(),
                                     new AnalyserNodeEngine(this),
                                     AudioNodeStream::NO_STREAM_FLAGS);
 
   // Enough chunks must be recorded to handle the case of fftSize being
   // increased to maximum immediately before getFloatTimeDomainData() is
   // called, for example.
-  (void)mChunks.SetLength(CHUNK_COUNT, fallible);
+  unused << mChunks.SetLength(CHUNK_COUNT, fallible);
 
   AllocateBuffer();
 }
 
 size_t
 AnalyserNode::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
 {
   size_t amount = AudioNode::SizeOfExcludingThis(aMallocSizeOf);
--- a/mfbt/Assertions.h
+++ b/mfbt/Assertions.h
@@ -489,15 +489,25 @@ struct AssertionConditionType
  * expression, in debug builds and in release builds both.  Then, in debug
  * builds only, the value of the expression is asserted either true or false
  * using MOZ_ASSERT.
  */
 #ifdef DEBUG
 #  define MOZ_ALWAYS_TRUE(expr)      MOZ_ASSERT((expr))
 #  define MOZ_ALWAYS_FALSE(expr)     MOZ_ASSERT(!(expr))
 #else
-#  define MOZ_ALWAYS_TRUE(expr)      ((void)(expr))
-#  define MOZ_ALWAYS_FALSE(expr)     ((void)(expr))
+#  define MOZ_ALWAYS_TRUE(expr) \
+  do { \
+    if (expr) { \
+      /* Silence MOZ_WARN_UNUSED_RESULT. */ \
+    } \
+  } while (0)
+#  define MOZ_ALWAYS_FALSE(expr) \
+  do { \
+    if (expr) { \
+      /* Silence MOZ_WARN_UNUSED_RESULT. */ \
+    } \
+  } while (0)
 #endif
 
 #undef MOZ_DUMP_ASSERTION_STACK
 
 #endif /* mozilla_Assertions_h */
--- a/storage/mozStorageBindingParams.cpp
+++ b/storage/mozStorageBindingParams.cpp
@@ -105,17 +105,17 @@ sqlite3_T_blob(BindingColumnData aData,
 
 BindingParams::BindingParams(mozIStorageBindingParamsArray *aOwningArray,
                              Statement *aOwningStatement)
 : mLocked(false)
 , mOwningArray(aOwningArray)
 , mOwningStatement(aOwningStatement)
 {
   (void)mOwningStatement->GetParameterCount(&mParamCount);
-  (void)mParameters.SetCapacity(mParamCount);
+  mParameters.SetCapacity(mParamCount);
 }
 
 BindingParams::BindingParams(mozIStorageBindingParamsArray *aOwningArray)
 : mLocked(false)
 , mOwningArray(aOwningArray)
 , mOwningStatement(nullptr)
 , mParamCount(0)
 {
--- a/toolkit/components/places/History.cpp
+++ b/toolkit/components/places/History.cpp
@@ -982,18 +982,18 @@ private:
                     nsTArray<VisitData>& aPlaces,
                     const nsMainThreadPtrHandle<mozIVisitInfoCallback>& aCallback)
   : mDBConn(aConnection)
   , mCallback(aCallback)
   , mHistory(History::GetService())
   {
     MOZ_ASSERT(NS_IsMainThread(), "This should be called on the main thread");
 
-    (void)mPlaces.SwapElements(aPlaces);
-    (void)mReferrers.SetLength(mPlaces.Length());
+    mPlaces.SwapElements(aPlaces);
+    mReferrers.SetLength(mPlaces.Length());
 
     for (nsTArray<VisitData>::size_type i = 0; i < mPlaces.Length(); i++) {
       mReferrers[i].spec = mPlaces[i].referrerSpec;
 
 #ifdef DEBUG
       nsCOMPtr<nsIURI> uri;
       (void)NS_NewURI(getter_AddRefs(uri), mPlaces[i].spec);
       NS_ASSERTION(CanAddURI(uri),
--- a/xpcom/glue/nsTArray.h
+++ b/xpcom/glue/nsTArray.h
@@ -1188,17 +1188,17 @@ public:
       const nsTArray_Impl<E, Allocator>& aOther)
   {
     return ActualAlloc::ConvertBoolToResultType(
       !!ReplaceElementsAt<E, ActualAlloc>(0, Length(),
                                           aOther.Elements(), aOther.Length()));
   }
 
   template<class Allocator>
-  /* MOZ_WARN_UNUSED_RESULT */
+  MOZ_WARN_UNUSED_RESULT
   bool Assign(const nsTArray_Impl<E, Allocator>& aOther,
               const mozilla::fallible_t&)
   {
     return Assign<Allocator, FallibleAlloc>(aOther);
   }
 
   template<class Allocator>
   void Assign(nsTArray_Impl<E, Allocator>&& aOther)
@@ -1269,17 +1269,17 @@ protected:
                                           sizeof(elem_type),
                                           MOZ_ALIGNOF(elem_type));
     AssignRange(aStart, aArrayLen, aArray);
     return Elements() + aStart;
   }
 public:
 
   template<class Item>
-  /* MOZ_WARN_UNUSED_RESULT */
+  MOZ_WARN_UNUSED_RESULT
   elem_type* ReplaceElementsAt(index_type aStart, size_type aCount,
                                const Item* aArray, size_type aArrayLen,
                                const mozilla::fallible_t&)
   {
     return ReplaceElementsAt<Item, FallibleAlloc>(aStart, aCount,
                                                   aArray, aArrayLen);
   }
 
@@ -1290,17 +1290,17 @@ protected:
                                const nsTArray<Item>& aArray)
   {
     return ReplaceElementsAt<Item, ActualAlloc>(
       aStart, aCount, aArray.Elements(), aArray.Length());
   }
 public:
 
   template<class Item>
-  /* MOZ_WARN_UNUSED_RESULT */
+  MOZ_WARN_UNUSED_RESULT
   elem_type* ReplaceElementsAt(index_type aStart, size_type aCount,
                                const nsTArray<Item>& aArray,
                                const mozilla::fallible_t&)
   {
     return ReplaceElementsAt<Item, FallibleAlloc>(aStart, aCount, aArray);
   }
 
   // A variation on the ReplaceElementsAt method defined above.
@@ -1309,17 +1309,17 @@ protected:
   elem_type* ReplaceElementsAt(index_type aStart, size_type aCount,
                                const Item& aItem)
   {
     return ReplaceElementsAt<Item, ActualAlloc>(aStart, aCount, &aItem, 1);
   }
 public:
 
   template<class Item>
-  /* MOZ_WARN_UNUSED_RESULT */
+  MOZ_WARN_UNUSED_RESULT
   elem_type* ReplaceElementsAt(index_type aStart, size_type aCount,
                                const Item& aItem, const mozilla::fallible_t&)
   {
     return ReplaceElementsAt<Item, FallibleAlloc>(aStart, aCount, aItem);
   }
 
   // A variation on the ReplaceElementsAt method defined above.
   template<class Item>
@@ -1334,17 +1334,17 @@ protected:
   elem_type* InsertElementsAt(index_type aIndex, const Item* aArray,
                               size_type aArrayLen)
   {
     return ReplaceElementsAt<Item, ActualAlloc>(aIndex, 0, aArray, aArrayLen);
   }
 public:
 
   template<class Item>
-  /* MOZ_WARN_UNUSED_RESULT */
+  MOZ_WARN_UNUSED_RESULT
   elem_type* InsertElementsAt(index_type aIndex, const Item* aArray,
                               size_type aArrayLen, const mozilla::fallible_t&)
   {
     return InsertElementsAt<Item, FallibleAlloc>(aIndex, aArray, aArrayLen);
   }
 
   // A variation on the ReplaceElementsAt method defined above.
 protected:
@@ -1353,17 +1353,17 @@ protected:
                               const nsTArray_Impl<Item, Allocator>& aArray)
   {
     return ReplaceElementsAt<Item, ActualAlloc>(
       aIndex, 0, aArray.Elements(), aArray.Length());
   }
 public:
 
   template<class Item, class Allocator>
-  /* MOZ_WARN_UNUSED_RESULT */
+  MOZ_WARN_UNUSED_RESULT
   elem_type* InsertElementsAt(index_type aIndex,
                               const nsTArray_Impl<Item, Allocator>& aArray,
                               const mozilla::fallible_t&)
   {
     return InsertElementsAt<Item, Allocator, FallibleAlloc>(aIndex, aArray);
   }
 
   // Insert a new element without copy-constructing. This is useful to avoid
@@ -1380,17 +1380,17 @@ protected:
     this->template ShiftData<ActualAlloc>(aIndex, 0, 1, sizeof(elem_type),
                                           MOZ_ALIGNOF(elem_type));
     elem_type* elem = Elements() + aIndex;
     elem_traits::Construct(elem);
     return elem;
   }
 public:
 
-  /* MOZ_WARN_UNUSED_RESULT */
+  MOZ_WARN_UNUSED_RESULT
   elem_type* InsertElementAt(index_type aIndex, const mozilla::fallible_t&)
   {
     return InsertElementAt<FallibleAlloc>(aIndex);
   }
 
   // Insert a new element, move constructing if possible.
 protected:
   template<class Item, typename ActualAlloc = Alloc>
@@ -1404,17 +1404,17 @@ protected:
                                           MOZ_ALIGNOF(elem_type));
     elem_type* elem = Elements() + aIndex;
     elem_traits::Construct(elem, mozilla::Forward<Item>(aItem));
     return elem;
   }
 public:
 
   template<class Item>
-  /* MOZ_WARN_UNUSED_RESULT */
+  MOZ_WARN_UNUSED_RESULT
   elem_type* InsertElementAt(index_type aIndex, Item&& aItem,
                              const mozilla::fallible_t&)
   {
     return InsertElementAt<Item, FallibleAlloc>(aIndex,
                                                 mozilla::Forward<Item>(aItem));
   }
 
   // This method searches for the smallest index of an element that is strictly
@@ -1461,17 +1461,17 @@ protected:
   {
     index_type index = IndexOfFirstElementGt<Item, Comparator>(aItem, aComp);
     return InsertElementAt<Item, ActualAlloc>(
       index, mozilla::Forward<Item>(aItem));
   }
 public:
 
   template<class Item, class Comparator>
-  /* MOZ_WARN_UNUSED_RESULT */
+  MOZ_WARN_UNUSED_RESULT
   elem_type* InsertElementSorted(Item&& aItem, const Comparator& aComp,
                                  const mozilla::fallible_t&)
   {
     return InsertElementSorted<Item, Comparator, FallibleAlloc>(
       mozilla::Forward<Item>(aItem), aComp);
   }
 
   // A variation on the InsertElementSorted method defined above.
@@ -1481,17 +1481,17 @@ protected:
   {
     nsDefaultComparator<elem_type, Item> comp;
     return InsertElementSorted<Item, decltype(comp), ActualAlloc>(
       mozilla::Forward<Item>(aItem), comp);
   }
 public:
 
   template<class Item>
-  /* MOZ_WARN_UNUSED_RESULT */
+  MOZ_WARN_UNUSED_RESULT
   elem_type* InsertElementSorted(Item&& aItem, const mozilla::fallible_t&)
   {
     return InsertElementSorted<Item, FallibleAlloc>(
       mozilla::Forward<Item>(aItem));
   }
 
   // This method appends elements to the end of this array.
   // @param aArray    The elements to append to this array.
@@ -1723,17 +1723,17 @@ protected:
   template<typename ActualAlloc = Alloc>
   typename ActualAlloc::ResultType SetCapacity(size_type aCapacity)
   {
     return ActualAlloc::Result(this->template EnsureCapacity<ActualAlloc>(
       aCapacity, sizeof(elem_type)));
   }
 public:
 
-  /* MOZ_WARN_UNUSED_RESULT */
+  MOZ_WARN_UNUSED_RESULT
   bool SetCapacity(size_type aCapacity, const mozilla::fallible_t&)
   {
     return SetCapacity<FallibleAlloc>(aCapacity);
   }
 
   // This method modifies the length of the array.  If the new length is
   // larger than the existing length of the array, then new elements will be
   // constructed using elem_type's default constructor.  Otherwise, this call
@@ -1752,17 +1752,17 @@ protected:
         InsertElementsAt<ActualAlloc>(oldLen, aNewLen - oldLen) != nullptr);
     }
 
     TruncateLength(aNewLen);
     return ActualAlloc::ConvertBoolToResultType(true);
   }
 public:
 
-  /* MOZ_WARN_UNUSED_RESULT */
+  MOZ_WARN_UNUSED_RESULT
   bool SetLength(size_type aNewLen, const mozilla::fallible_t&)
   {
     return SetLength<FallibleAlloc>(aNewLen);
   }
 
   // This method modifies the length of the array, but may only be
   // called when the new length is shorter than the old.  It can
   // therefore be called when elem_type has no default constructor,
@@ -1791,17 +1791,17 @@ protected:
     if (aMinLen > oldLen) {
       return ActualAlloc::ConvertBoolToResultType(
         !!InsertElementsAt<ActualAlloc>(oldLen, aMinLen - oldLen));
     }
     return ActualAlloc::ConvertBoolToResultType(true);
   }
 public:
 
-  /* MOZ_WARN_UNUSED_RESULT */
+  MOZ_WARN_UNUSED_RESULT
   bool EnsureLengthAtLeast(size_type aMinLen, const mozilla::fallible_t&)
   {
     return EnsureLengthAtLeast<FallibleAlloc>(aMinLen);
   }
 
   // This method inserts elements into the array, constructing
   // them using elem_type's default constructor.
   // @param aIndex the place to insert the new elements. This must be no
@@ -1823,17 +1823,17 @@ protected:
     for (; iter != iend; ++iter) {
       elem_traits::Construct(iter);
     }
 
     return Elements() + aIndex;
   }
 public:
 
-  /* MOZ_WARN_UNUSED_RESULT */
+  MOZ_WARN_UNUSED_RESULT
   elem_type* InsertElementsAt(index_type aIndex, size_type aCount,
                               const mozilla::fallible_t&)
   {
     return InsertElementsAt<FallibleAlloc>(aIndex, aCount);
   }
 
   // This method inserts elements into the array, constructing them
   // elem_type's copy constructor (or whatever one-arg constructor
@@ -1860,17 +1860,17 @@ protected:
       elem_traits::Construct(iter, aItem);
     }
 
     return Elements() + aIndex;
   }
 public:
 
   template<class Item>
-  /* MOZ_WARN_UNUSED_RESULT */
+  MOZ_WARN_UNUSED_RESULT
   elem_type* InsertElementsAt(index_type aIndex, size_type aCount,
                               const Item& aItem, const mozilla::fallible_t&)
   {
     return InsertElementsAt<Item, FallibleAlloc>(aIndex, aCount, aItem);
   }
 
   // This method may be called to minimize the memory used by this array.
   void Compact()
--- a/xpcom/tests/TestTArray.cpp
+++ b/xpcom/tests/TestTArray.cpp
@@ -1,15 +1,16 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim:set ts=2 sw=2 sts=2 et cindent: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/ArrayUtils.h"
+#include "mozilla/unused.h"
 
 #include <stdlib.h>
 #include <stdio.h>
 #include <iostream>
 #include "nsTArray.h"
 #include "nsAutoPtr.h"
 #include "nsStringAPI.h"
 #include "nsDirectoryServiceDefs.h"
@@ -1110,19 +1111,19 @@ static bool test_SetLengthAndRetainStora
   do {                                                         \
     pre f post;                                                \
     pre fauto post;                                            \
     pre i post;                                                \
     pre iauto post;                                            \
     pre t post;                                                \
     pre tauto post;                                            \
   } while (0)
-  
+
   // Setup test arrays.
-  FOR_EACH(;, .SetLength(N, fallible));
+  FOR_EACH(; unused << , .SetLength(N, fallible));
   for (int n = 0; n < N; ++n) {
     FOR_EACH(;, [n] = n);
   }
 
   void* initial_Hdrs[] = {
     static_cast<BufAccessor<FallibleTArray<int> >&>(f).GetHdr(),
     static_cast<BufAccessor<AutoFallibleTArray<int, N> >&>(fauto).GetHdr(),
     static_cast<BufAccessor<InfallibleTArray<int> >&>(i).GetHdr(),