Bug 1253094, part 11 - Make DebugOnly a MOZ_STACK_CLASS. r=Waldo
authorJonathan Watt <jwatt@jwatt.org>
Fri, 26 Feb 2016 15:52:08 +0000
changeset 325000 58475d84315a54c9bda2dd19f9f0b9d1b4cb9ac2
parent 324999 4479c6c67ec5e0061e0b70f1f3ff01f5a48a70ea
child 325001 98c44d678dc30261b2e3590cb238129c4bbd3bc6
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersWaldo
bugs1253094
milestone47.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 1253094, part 11 - Make DebugOnly a MOZ_STACK_CLASS. r=Waldo MozReview-Commit-ID: I09tdRotoJq
mfbt/DebugOnly.h
--- a/mfbt/DebugOnly.h
+++ b/mfbt/DebugOnly.h
@@ -19,28 +19,29 @@ 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();
  *   MOZ_ASSERT(check);
  *
- * more concisely than declaring |check| conditional on #ifdef DEBUG, but also
- * without allocating storage space for |check| in release builds.
+ * more concisely than declaring |check| conditional on #ifdef DEBUG.
  *
  * DebugOnly instances can only be coerced to T in debug builds.  In release
  * builds they don't have a value, so type coercion is not well defined.
  *
- * NOTE! DebugOnly instances still take up one byte of space, plus padding, even
- * in optimized, non-DEBUG builds.  Don't use DebugOnly for struct/class members
- * unless that really doesn't matter to you.
+ * NOTE: DebugOnly instances still take up one byte of space, plus padding, even
+ * in optimized, non-DEBUG builds (see bug 1253094 comment 37 for more info).
+ * For this reason the class is MOZ_STACK_CLASS to prevent consumers using
+ * DebugOnly for struct/class members and unwittingly inflating the size of
+ * their objects in release builds.
  */
 template<typename T>
-class DebugOnly
+class MOZ_STACK_CLASS DebugOnly
 {
 public:
 #ifdef DEBUG
   T value;
 
   DebugOnly() { }
   MOZ_IMPLICIT DebugOnly(const T& aOther) : value(aOther) { }
   DebugOnly(const DebugOnly& aOther) : value(aOther.value) { }