Bug 1661497 - Make DebugOnly work with move-only value types. r=froydnj
☠☠ backed out by 603459fd7f34 ☠ ☠
authorSimon Giesecke <sgiesecke@mozilla.com>
Wed, 02 Sep 2020 16:22:38 +0000
changeset 547527 733df139089ab134647f33ccb1b18130ccd3f942
parent 547526 fca770fc0956525d8b1809e7b95c5d5717bceb9e
child 547528 8a9dce0d08ce806a5ded605cc4dc016b89f7a555
push id125591
push usersgiesecke@mozilla.com
push dateWed, 02 Sep 2020 16:34:28 +0000
treeherderautoland@fbf42b3b51f3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1661497
milestone82.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 1661497 - Make DebugOnly work with move-only value types. r=froydnj Differential Revision: https://phabricator.services.mozilla.com/D88442
mfbt/DebugOnly.h
--- a/mfbt/DebugOnly.h
+++ b/mfbt/DebugOnly.h
@@ -9,16 +9,18 @@
  * assertions).
  */
 
 #ifndef mozilla_DebugOnly_h
 #define mozilla_DebugOnly_h
 
 #include "mozilla/Attributes.h"
 
+#include <utility>
+
 namespace mozilla {
 
 /**
  * DebugOnly contains a value of type T, but only in debug builds.  In release
  * builds, it does not contain a value.  This helper is intended to be used with
  * MOZ_ASSERT()-style macros, allowing one to write:
  *
  *   DebugOnly<bool> check = func();
@@ -37,22 +39,27 @@ namespace mozilla {
  */
 template <typename T>
 class MOZ_STACK_CLASS DebugOnly {
  public:
 #ifdef DEBUG
   T value;
 
   DebugOnly() = default;
+  MOZ_IMPLICIT DebugOnly(T&& aOther) : value(std::move(aOther)) {}
   MOZ_IMPLICIT DebugOnly(const T& aOther) : value(aOther) {}
   DebugOnly(const DebugOnly& aOther) : value(aOther.value) {}
   DebugOnly& operator=(const T& aRhs) {
     value = aRhs;
     return *this;
   }
+  DebugOnly& operator=(T&& aRhs) {
+    value = std::move(aRhs);
+    return *this;
+  }
 
   void operator++(int) { value++; }
   void operator--(int) { value--; }
 
   // Do not define operator+=(), etc. here.  These will coerce via the
   // implicit cast and built-in operators.  Defining explicit methods here
   // will create ambiguity the compiler can't deal with.
 
@@ -64,16 +71,18 @@ class MOZ_STACK_CLASS DebugOnly {
   T& operator->() { return value; }
   const T& operator->() const { return value; }
 
 #else
   DebugOnly() = default;
   MOZ_IMPLICIT DebugOnly(const T&) {}
   DebugOnly(const DebugOnly&) {}
   DebugOnly& operator=(const T&) { return *this; }
+  DebugOnly(T&&) {}
+  DebugOnly& operator=(T&&) { return *this; }
   void operator++(int) {}
   void operator--(int) {}
   DebugOnly& operator+=(const T&) { return *this; }
   DebugOnly& operator-=(const T&) { return *this; }
   DebugOnly& operator&=(const T&) { return *this; }
   DebugOnly& operator|=(const T&) { return *this; }
   DebugOnly& operator^=(const T&) { return *this; }
 #endif