Bug 1156407 - part 1 - use static_assert instead of PR_STATIC_ASSERT; r=mccr8
authorNathan Froyd <froydnj@mozilla.com>
Mon, 20 Apr 2015 13:56:46 -0400
changeset 240234 3c01ad35ec780b9a05c3d25ee728056509d3f5dd
parent 240233 39fcae4f958db22e4c4b3261598df4b3e8bd7e88
child 240235 5e813775efd8da179920ce8a18f61932f7e1ffd3
push idunknown
push userunknown
push dateunknown
reviewersmccr8
bugs1156407
milestone40.0a1
Bug 1156407 - part 1 - use static_assert instead of PR_STATIC_ASSERT; r=mccr8 We have better, C++-ier ways of doing compile-time assertions now. Fold in the nsTSubstring.cpp change in passing, since mccr8 suggested it in his review.
xpcom/string/nsTSubstring.cpp
xpcom/threads/nsTimerImpl.h
--- a/xpcom/string/nsTSubstring.cpp
+++ b/xpcom/string/nsTSubstring.cpp
@@ -48,17 +48,18 @@ nsTSubstring_CharT::MutatePrep(size_type
   *aOldData = nullptr;
   *aOldFlags = 0;
 
   size_type curCapacity = Capacity();
 
   // If |aCapacity > kMaxCapacity|, then our doubling algorithm may not be
   // able to allocate it.  Just bail out in cases like that.  We don't want
   // to be allocating 2GB+ strings anyway.
-  PR_STATIC_ASSERT((sizeof(nsStringBuffer) & 0x1) == 0);
+  static_assert((sizeof(nsStringBuffer) & 0x1) == 0,
+                "bad size for nsStringBuffer");
   const size_type kMaxCapacity =
     (size_type(-1) / 2 - sizeof(nsStringBuffer)) / sizeof(char_type) - 2;
   if (aCapacity > kMaxCapacity) {
     // Also assert for |aCapacity| equal to |size_type(-1)|, since we used to
     // use that value to flag immutability.
     NS_ASSERTION(aCapacity != size_type(-1), "Bogus capacity");
     return false;
   }
--- a/xpcom/threads/nsTimerImpl.h
+++ b/xpcom/threads/nsTimerImpl.h
@@ -96,19 +96,22 @@ private:
       NS_RELEASE(mCallback.i);
     } else if (cbType == CALLBACK_TYPE_OBSERVER) {
       NS_RELEASE(mCallback.o);
     }
   }
 
   bool IsRepeating() const
   {
-    PR_STATIC_ASSERT(TYPE_ONE_SHOT < TYPE_REPEATING_SLACK);
-    PR_STATIC_ASSERT(TYPE_REPEATING_SLACK < TYPE_REPEATING_PRECISE);
-    PR_STATIC_ASSERT(TYPE_REPEATING_PRECISE < TYPE_REPEATING_PRECISE_CAN_SKIP);
+    static_assert(TYPE_ONE_SHOT < TYPE_REPEATING_SLACK,
+                  "invalid ordering of timer types!");
+    static_assert(TYPE_REPEATING_SLACK < TYPE_REPEATING_PRECISE,
+                  "invalid ordering of timer types!");
+    static_assert(TYPE_REPEATING_PRECISE < TYPE_REPEATING_PRECISE_CAN_SKIP,
+                  "invalid ordering of timer types!");
     return mType >= TYPE_REPEATING_SLACK;
   }
 
   bool IsRepeatingPrecisely() const
   {
     return mType >= TYPE_REPEATING_PRECISE;
   }