Bug 1010634, Part 2: Fix compiler warnings in MFBT and XPCOM, r=ehsan
authorBrian Smith <brian@briansmith.org>
Thu, 29 May 2014 20:18:29 -0700
changeset 185930 20f228f5a33d18619e5199000cdd3d8dcc7ee086
parent 185926 3ac2205532ed66999c8fa7b25d42f8ccb7908617
child 185931 e1f531152b770898d133e606d1ff746600393a72
push id26871
push userphilringnalda@gmail.com
push dateSun, 01 Jun 2014 03:29:42 +0000
treeherdermozilla-central@0e10c8151654 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs1010634
milestone32.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 1010634, Part 2: Fix compiler warnings in MFBT and XPCOM, r=ehsan
mfbt/MathAlgorithms.h
xpcom/glue/DeadlockDetector.h
xpcom/glue/nsTArray.h
xpcom/string/public/nsCharTraits.h
xpcom/string/public/nsReadableUtils.h
--- a/mfbt/MathAlgorithms.h
+++ b/mfbt/MathAlgorithms.h
@@ -200,32 +200,32 @@ namespace detail {
 #  if defined(MOZ_BITSCAN_WINDOWS64)
     unsigned long index;
     _BitScanReverse64(&index, static_cast<unsigned __int64>(u));
     return uint_fast8_t(63 - index);
 #  else
     uint32_t hi = uint32_t(u >> 32);
     if (hi != 0)
       return CountLeadingZeroes32(hi);
-    return 32 + CountLeadingZeroes32(uint32_t(u));
+    return 32u + CountLeadingZeroes32(uint32_t(u));
 #  endif
   }
 
   inline uint_fast8_t
   CountTrailingZeroes64(uint64_t u)
   {
 #  if defined(MOZ_BITSCAN_WINDOWS64)
     unsigned long index;
     _BitScanForward64(&index, static_cast<unsigned __int64>(u));
     return uint_fast8_t(index);
 #  else
     uint32_t lo = uint32_t(u);
     if (lo != 0)
       return CountTrailingZeroes32(lo);
-    return 32 + CountTrailingZeroes32(uint32_t(u >> 32));
+    return 32u + CountTrailingZeroes32(uint32_t(u >> 32));
 #  endif
   }
 
 #  ifdef MOZ_HAVE_BITSCAN64
 #    undef MOZ_HAVE_BITSCAN64
 #  endif
 
 #elif defined(__clang__) || defined(__GNUC__)
@@ -346,17 +346,17 @@ template<typename T, size_t Size = sizeo
 class CeilingLog2;
 
 template<typename T>
 class CeilingLog2<T, 4>
 {
   public:
     static uint_fast8_t compute(const T t) {
       // Check for <= 1 to avoid the == 0 undefined case.
-      return t <= 1 ? 0 : 32 - CountLeadingZeroes32(t - 1);
+      return t <= 1 ? 0u : 32u - CountLeadingZeroes32(t - 1);
     }
 };
 
 template<typename T>
 class CeilingLog2<T, 8>
 {
   public:
     static uint_fast8_t compute(const T t) {
@@ -395,26 +395,26 @@ namespace detail {
 template<typename T, size_t Size = sizeof(T)>
 class FloorLog2;
 
 template<typename T>
 class FloorLog2<T, 4>
 {
   public:
     static uint_fast8_t compute(const T t) {
-      return 31 - CountLeadingZeroes32(t | 1);
+      return 31u - CountLeadingZeroes32(t | 1);
     }
 };
 
 template<typename T>
 class FloorLog2<T, 8>
 {
   public:
     static uint_fast8_t compute(const T t) {
-      return 63 - CountLeadingZeroes64(t | 1);
+      return 63u - CountLeadingZeroes64(t | 1);
     }
 };
 
 } // namespace detail
 
 /**
  * Compute the log of the greatest power of 2 less than or equal to |t|.
  *
--- a/xpcom/glue/DeadlockDetector.h
+++ b/xpcom/glue/DeadlockDetector.h
@@ -222,17 +222,17 @@ private:
         delete static_cast<T*>(const_cast<void*>(entry->key));
         delete static_cast<OrderingEntry*>(entry->value);
         entry->value = 0;
         if (HT_FREE_ENTRY == flag)
             delete entry;
     }
     static PLHashNumber HashKey(const void* aKey)
     {
-        return NS_PTR_TO_INT32(aKey) >> 2;
+        return static_cast<PLHashNumber>(NS_PTR_TO_INT32(aKey) >> 2);
     }
     static const PLHashAllocOps kAllocOps;
 
     // Hash table "interface" the rest of the code should use
 
     PLHashEntry** GetEntry(const T* aKey)
     {
         return PL_HashTableRawLookup(mOrdering, HashKey(aKey), aKey);
--- a/xpcom/glue/nsTArray.h
+++ b/xpcom/glue/nsTArray.h
@@ -746,19 +746,17 @@ public:
   typedef nsTArrayElementTraits<E>                   elem_traits;
   typedef nsTArray_SafeElementAtHelper<E, self_type> safeelementat_helper_type;
 
   using safeelementat_helper_type::SafeElementAt;
   using base_type::EmptyHdr;
 
   // A special value that is used to indicate an invalid or unknown index
   // into the array.
-  enum {
-    NoIndex = index_type(-1)
-  };
+  static const index_type NoIndex = index_type(-1);
 
   using base_type::Length;
 
   //
   // Finalization method
   //
 
   ~nsTArray_Impl() { Clear(); }
--- a/xpcom/string/public/nsCharTraits.h
+++ b/xpcom/string/public/nsCharTraits.h
@@ -157,17 +157,17 @@ struct nsCharTraits<char16_t>
                                           aN * sizeof(char_type)));
   }
 
   static char_type*
   copyASCII(char_type* aStr1, const char* aStr2, size_t aN)
   {
     for (char_type* s = aStr1; aN--; ++s, ++aStr2) {
       NS_ASSERTION(!(*aStr2 & ~0x7F), "Unexpected non-ASCII character");
-      *s = *aStr2;
+      *s = static_cast<char_type>(*aStr2);
     }
     return aStr1;
   }
 
   static char_type*
   assign(char_type* aStr, size_t aN, char_type aChar)
   {
     char_type* result = aStr;
@@ -189,18 +189,20 @@ struct nsCharTraits<char16_t>
     return 0;
   }
 
   static int
   compareASCII(const char_type* aStr1, const char* aStr2, size_t aN)
   {
     for (; aN--; ++aStr1, ++aStr2) {
       NS_ASSERTION(!(*aStr2 & ~0x7F), "Unexpected non-ASCII character");
-      if (!eq_int_type(to_int_type(*aStr1), to_int_type(*aStr2))) {
-        return to_int_type(*aStr1) - to_int_type(*aStr2);
+      if (!eq_int_type(to_int_type(*aStr1),
+                       to_int_type(static_cast<char_type>(*aStr2)))) {
+        return to_int_type(*aStr1) -
+               to_int_type(static_cast<char_type>(*aStr2));
       }
     }
 
     return 0;
   }
 
   // this version assumes that s2 is null-terminated and s1 has length n.
   // if s1 is shorter than s2 then we return -1; if s1 is longer than s2,
@@ -209,18 +211,20 @@ struct nsCharTraits<char16_t>
   compareASCIINullTerminated(const char_type* aStr1, size_t aN,
                              const char* aStr2)
   {
     for (; aN--; ++aStr1, ++aStr2) {
       if (!*aStr2) {
         return 1;
       }
       NS_ASSERTION(!(*aStr2 & ~0x7F), "Unexpected non-ASCII character");
-      if (!eq_int_type(to_int_type(*aStr1), to_int_type(*aStr2))) {
-        return to_int_type(*aStr1) - to_int_type(*aStr2);
+      if (!eq_int_type(to_int_type(*aStr1),
+                       to_int_type(static_cast<char_type>(*aStr2)))) {
+        return to_int_type(*aStr1) -
+               to_int_type(static_cast<char_type>(*aStr2));
       }
     }
 
     if (*aStr2) {
       return -1;
     }
 
     return 0;
@@ -243,18 +247,19 @@ struct nsCharTraits<char16_t>
   static int
   compareLowerCaseToASCII(const char_type* aStr1, const char* aStr2, size_t aN)
   {
     for (; aN--; ++aStr1, ++aStr2) {
       NS_ASSERTION(!(*aStr2 & ~0x7F), "Unexpected non-ASCII character");
       NS_ASSERTION(!(*aStr2 >= 'A' && *aStr2 <= 'Z'),
                    "Unexpected uppercase character");
       char_type lower_s1 = ASCIIToLower(*aStr1);
-      if (lower_s1 != to_char_type(*aStr2)) {
-        return to_int_type(lower_s1) - to_int_type(*aStr2);
+      if (lower_s1 != static_cast<char_type>(*aStr2)) {
+        return to_int_type(lower_s1) -
+               to_int_type(static_cast<char_type>(*aStr2));
       }
     }
 
     return 0;
   }
 
   // this version assumes that s2 is null-terminated and s1 has length n.
   // if s1 is shorter than s2 then we return -1; if s1 is longer than s2,
@@ -266,18 +271,19 @@ struct nsCharTraits<char16_t>
     for (; aN--; ++aStr1, ++aStr2) {
       if (!*aStr2) {
         return 1;
       }
       NS_ASSERTION(!(*aStr2 & ~0x7F), "Unexpected non-ASCII character");
       NS_ASSERTION(!(*aStr2 >= 'A' && *aStr2 <= 'Z'),
                    "Unexpected uppercase character");
       char_type lower_s1 = ASCIIToLower(*aStr1);
-      if (lower_s1 != to_char_type(*aStr2)) {
-        return to_int_type(lower_s1) - to_int_type(*aStr2);
+      if (lower_s1 != static_cast<char_type>(*aStr2)) {
+        return to_int_type(lower_s1) -
+               to_int_type(static_cast<char_type>(*aStr2));
       }
     }
 
     if (*aStr2) {
       return -1;
     }
 
     return 0;
--- a/xpcom/string/public/nsReadableUtils.h
+++ b/xpcom/string/public/nsReadableUtils.h
@@ -8,31 +8,34 @@
 #ifndef nsReadableUtils_h___
 #define nsReadableUtils_h___
 
 /**
  * I guess all the routines in this file are all mis-named.
  * According to our conventions, they should be |NS_xxx|.
  */
 
+#include "mozilla/Assertions.h"
 #include "nsAString.h"
 
 #include "nsTArrayForwardDeclare.h"
 
 inline size_t
 Distance(const nsReadingIterator<char16_t>& aStart,
          const nsReadingIterator<char16_t>& aEnd)
 {
-  return aEnd.get() - aStart.get();
+  MOZ_ASSERT(aStart.get() <= aEnd.get());
+  return static_cast<size_t>(aEnd.get() - aStart.get());
 }
 inline size_t
 Distance(const nsReadingIterator<char>& aStart,
          const nsReadingIterator<char>& aEnd)
 {
-  return aEnd.get() - aStart.get();
+  MOZ_ASSERT(aStart.get() <= aEnd.get());
+  return static_cast<size_t>(aEnd.get() - aStart.get());
 }
 
 void LossyCopyUTF16toASCII(const nsAString& aSource, nsACString& aDest);
 void CopyASCIItoUTF16(const nsACString& aSource, nsAString& aDest);
 
 void LossyCopyUTF16toASCII(const char16_t* aSource, nsACString& aDest);
 void CopyASCIItoUTF16(const char* aSource, nsAString& aDest);