Bug 1253094, part 11 - Make DebugOnly a MOZ_STACK_ONLY class. r=Waldo draft
authorJonathan Watt <jwatt@jwatt.org>
Wed, 02 Mar 2016 23:59:39 +0000
changeset 336262 ad10c952167c3b7f2a6dff5c19026720d2affc31
parent 336261 62674595ac8cdbff258558dbfc0462a8d6ce9227
child 515357 96ca0c19a2dea22c50fa51a4b840254dce0ad922
push id12025
push userjwatt@jwatt.org
push dateThu, 03 Mar 2016 00:03:10 +0000
reviewersWaldo
bugs1253094
milestone47.0a1
Bug 1253094, part 11 - Make DebugOnly a MOZ_STACK_ONLY class. r=Waldo MozReview-Commit-ID: 1rMdDCYySJf
mfbt/DebugOnly.h
--- a/mfbt/DebugOnly.h
+++ b/mfbt/DebugOnly.h
@@ -19,28 +19,28 @@ 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.  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) { }