mfbt/double-conversion/use-static_assert.patch

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

michael@0 1 diff --git a/mfbt/double-conversion/utils.h b/mfbt/double-conversion/utils.h
michael@0 2 --- a/mfbt/double-conversion/utils.h
michael@0 3 +++ b/mfbt/double-conversion/utils.h
michael@0 4 @@ -275,19 +275,18 @@ class StringBuilder {
michael@0 5 // There is an additional use for BitCast.
michael@0 6 // Recent gccs will warn when they see casts that may result in breakage due to
michael@0 7 // the type-based aliasing rule. If you have checked that there is no breakage
michael@0 8 // you can use BitCast to cast one pointer type to another. This confuses gcc
michael@0 9 // enough that it can no longer see that you have cast one pointer type to
michael@0 10 // another thus avoiding the warning.
michael@0 11 template <class Dest, class Source>
michael@0 12 inline Dest BitCast(const Source& source) {
michael@0 13 - // Compile time assertion: sizeof(Dest) == sizeof(Source)
michael@0 14 - // A compile error here means your Dest and Source have different sizes.
michael@0 15 - typedef char VerifySizesAreEqual[sizeof(Dest) == sizeof(Source) ? 1 : -1];
michael@0 16 + static_assert(sizeof(Dest) == sizeof(Source),
michael@0 17 + "BitCast's source and destination types must be the same size");
michael@0 18
michael@0 19 Dest dest;
michael@0 20 memmove(&dest, &source, sizeof(dest));
michael@0 21 return dest;
michael@0 22 }
michael@0 23
michael@0 24 template <class Dest, class Source>
michael@0 25 inline Dest BitCast(Source* source) {

mercurial