Bug 919337: Use static_assert in double_conversion::BitCast. r=waldo
authorJim Blandy <jimb@mozilla.com>
Sun, 29 Sep 2013 21:18:26 -0700
changeset 149212 4d4a7fd7d375a9f711d508c3938339e7228a28e7
parent 149211 cd5ae0c57f7d3a5db46499e4e6596fabd40af2ca
child 149213 b85ed93dee3b409e1b69c9f6de0cd98ba57cca1f
push id2881
push useremorley@mozilla.com
push dateMon, 30 Sep 2013 16:21:19 +0000
treeherderfx-team@c088ab1e2d8b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswaldo
bugs919337
milestone27.0a1
Bug 919337: Use static_assert in double_conversion::BitCast. r=waldo
mfbt/double-conversion/update.sh
mfbt/double-conversion/use-static_assert.patch
mfbt/double-conversion/utils.h
--- a/mfbt/double-conversion/update.sh
+++ b/mfbt/double-conversion/update.sh
@@ -14,8 +14,9 @@ cp $1/README ./
 cp $1/src/*.h ./
 
 # Source
 cp $1/src/*.cc ./
 
 patch -p3 < add-mfbt-api-markers.patch
 patch -p3 < use-StandardInteger.patch
 patch -p3 < use-mozilla-assertions.patch
+patch -p3 < use-static_assert.patch
new file mode 100644
--- /dev/null
+++ b/mfbt/double-conversion/use-static_assert.patch
@@ -0,0 +1,25 @@
+diff --git a/mfbt/double-conversion/utils.h b/mfbt/double-conversion/utils.h
+--- a/mfbt/double-conversion/utils.h
++++ b/mfbt/double-conversion/utils.h
+@@ -275,19 +275,18 @@ class StringBuilder {
+ // There is an additional use for BitCast.
+ // Recent gccs will warn when they see casts that may result in breakage due to
+ // the type-based aliasing rule.  If you have checked that there is no breakage
+ // you can use BitCast to cast one pointer type to another.  This confuses gcc
+ // enough that it can no longer see that you have cast one pointer type to
+ // another thus avoiding the warning.
+ template <class Dest, class Source>
+ inline Dest BitCast(const Source& source) {
+-  // Compile time assertion: sizeof(Dest) == sizeof(Source)
+-  // A compile error here means your Dest and Source have different sizes.
+-  typedef char VerifySizesAreEqual[sizeof(Dest) == sizeof(Source) ? 1 : -1];
++  static_assert(sizeof(Dest) == sizeof(Source),
++                "BitCast's source and destination types must be the same size");
+ 
+   Dest dest;
+   memmove(&dest, &source, sizeof(dest));
+   return dest;
+ }
+ 
+ template <class Dest, class Source>
+ inline Dest BitCast(Source* source) {
--- a/mfbt/double-conversion/utils.h
+++ b/mfbt/double-conversion/utils.h
@@ -275,19 +275,18 @@ class StringBuilder {
 // There is an additional use for BitCast.
 // Recent gccs will warn when they see casts that may result in breakage due to
 // the type-based aliasing rule.  If you have checked that there is no breakage
 // you can use BitCast to cast one pointer type to another.  This confuses gcc
 // enough that it can no longer see that you have cast one pointer type to
 // another thus avoiding the warning.
 template <class Dest, class Source>
 inline Dest BitCast(const Source& source) {
-  // Compile time assertion: sizeof(Dest) == sizeof(Source)
-  // A compile error here means your Dest and Source have different sizes.
-  typedef char VerifySizesAreEqual[sizeof(Dest) == sizeof(Source) ? 1 : -1];
+  static_assert(sizeof(Dest) == sizeof(Source),
+                "BitCast's source and destination types must be the same size");
 
   Dest dest;
   memmove(&dest, &source, sizeof(dest));
   return dest;
 }
 
 template <class Dest, class Source>
 inline Dest BitCast(Source* source) {