Bug 1442967 - Boo, MSVC warns when a cast will truncate a numeric constant. Arguably a desirable warning generally, but here we specifically intend the cast to narrow, so disable the warning. r=me in a CLOSED TREE a=test-only
authorJeff Walden <jwalden@mit.edu>
Mon, 12 Mar 2018 19:20:42 -0700
changeset 462626 e485f830866050893a002e7dcfd5e2ff202b10cc
parent 462625 960411415e42b8cadfeb60a49e58af3b0dd260d8
child 462627 9778baa298b05f5a2292ba3c83f5310ea8936119
push id1683
push usersfraser@mozilla.com
push dateThu, 26 Apr 2018 16:43:40 +0000
treeherdermozilla-release@5af6cb21869d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersme, test-only
bugs1442967
milestone60.0
Bug 1442967 - Boo, MSVC warns when a cast will truncate a numeric constant. Arguably a desirable warning generally, but here we specifically intend the cast to narrow, so disable the warning. r=me in a CLOSED TREE a=test-only
mfbt/tests/TestEndian.cpp
--- a/mfbt/tests/TestEndian.cpp
+++ b/mfbt/tests/TestEndian.cpp
@@ -363,22 +363,33 @@ main()
     BigEndian::readUint32(&unsigned_bytes[0]) == 0x01020304U);
 
   MOZ_RELEASE_ASSERT(
     LittleEndian::readUint64(&unsigned_bytes[0]) == 0x0807060504030201ULL);
   MOZ_RELEASE_ASSERT(
     BigEndian::readUint64(&unsigned_bytes[0]) == 0x0102030405060708ULL);
 
   if (sizeof(uintptr_t) == 8) {
+    // MSVC warning C4309 is "'static_cast': truncation of constant value" and
+    // will hit for the literal casts below in 32-bit builds -- in dead code,
+    // because only the other arm of this |if| runs.  Turn off the warning for
+    // these two uses in dead code.
+#ifdef _MSC_VER
+#  pragma warning(push)
+#  pragma warning(disable: 4309)
+#endif
     MOZ_RELEASE_ASSERT(
       LittleEndian::readUintptr(&unsigned_bytes[0]) ==
       static_cast<uintptr_t>(0x0807060504030201ULL));
     MOZ_RELEASE_ASSERT(
       BigEndian::readUintptr(&unsigned_bytes[0]) ==
       static_cast<uintptr_t>(0x0102030405060708ULL));
+#ifdef _MSC_VER
+#  pragma warning(pop)
+#endif
   } else {
     MOZ_RELEASE_ASSERT(
       LittleEndian::readUintptr(&unsigned_bytes[0]) == 0x04030201U);
     MOZ_RELEASE_ASSERT(
       BigEndian::readUintptr(&unsigned_bytes[0]) == 0x01020304U);
   }
 
   LittleEndian::writeUint16(&buffer[0], 0x0201);