Bug 832788. Part 4: PrimitiveConversions should avoid implicit narrowing casts to avoid compiler warnings; make them explicit. r=bzbarsky
authorRobert O'Callahan <robert@ocallahan.org>
Tue, 29 Jan 2013 16:14:40 +1300
changeset 120183 7e9f3cc6cc0ac284d864fc6feb6a68bf6abb060f
parent 120182 cfd6d79d73fa71773853d92d7ce6440c171e6bc8
child 120184 9f088fcd80801c88aeb3921a4e170f163d702db1
push id24239
push userryanvm@gmail.com
push dateTue, 29 Jan 2013 14:36:31 +0000
treeherdermozilla-central@d3a5e1de98b0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbzbarsky
bugs832788
milestone21.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 832788. Part 4: PrimitiveConversions should avoid implicit narrowing casts to avoid compiler warnings; make them explicit. r=bzbarsky
dom/bindings/PrimitiveConversions.h
--- a/dom/bindings/PrimitiveConversions.h
+++ b/dom/bindings/PrimitiveConversions.h
@@ -268,17 +268,17 @@ PrimitiveConversionTraits_Clamp(JSContex
 
   // Banker's rounding (round ties towards even).
   // We move away from 0 by 0.5f and then truncate.  That gets us the right
   // answer for any starting value except plus or minus N.5.  With a starting
   // value of that form, we now have plus or minus N+1.  If N is odd, this is
   // the correct result.  If N is even, plus or minus N is the correct result.
   double toTruncate = (d < 0) ? d - 0.5 : d + 0.5;
 
-  T truncated(toTruncate);
+  T truncated = static_cast<T>(toTruncate);
 
   if (truncated == toTruncate) {
     /*
      * It was a tie (since moving away from 0 by 0.5 gave us the exact integer
      * we want). Since we rounded away from 0, we either already have an even
      * number or we have an odd number but the number we want is one closer to
      * 0. So just unconditionally masking out the ones bit should do the trick
      * to get us the value we want.
@@ -334,17 +334,17 @@ struct PrimitiveConversionTraits<double,
 
 template<typename T, ConversionBehavior B>
 bool ValueToPrimitive(JSContext* cx, JS::Value v, T* retval)
 {
   typename PrimitiveConversionTraits<T, B>::jstype t;
   if (!PrimitiveConversionTraits<T, B>::converter(cx, v, &t))
     return false;
 
-  *retval =
-    static_cast<typename PrimitiveConversionTraits<T, B>::intermediateType>(t);
+  *retval = static_cast<T>(
+    static_cast<typename PrimitiveConversionTraits<T, B>::intermediateType>(t));
   return true;
 }
 
 } // namespace dom
 } // namespace mozilla
 
 #endif /* mozilla_dom_PrimitiveConversions_h */