Bug 904985, part 1: Add better support for char16_t in type traits, r=Waldo.
authorJoshua Cranmer <Pidgeot18@gmail.com>
Tue, 17 Sep 2013 22:43:04 -0500
changeset 161494 11af1e7c053fca4335554f74bae45ed0343fb6f1
parent 161493 4b54782ad3ffeff188d098282776a509a40eb552
child 161495 0a62484ff46bb8ed6d3bb173ab04bc46c62b659b
push id3066
push userakeybl@mozilla.com
push dateMon, 09 Dec 2013 19:58:46 +0000
treeherdermozilla-beta@a31a0dce83aa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersWaldo
bugs904985
milestone27.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 904985, part 1: Add better support for char16_t in type traits, r=Waldo.
mfbt/Char16.h
mfbt/TypeTraits.h
--- a/mfbt/Char16.h
+++ b/mfbt/Char16.h
@@ -31,27 +31,33 @@
     */
 #  define MOZ_UTF16_HELPER(s) L##s
 #  include <yvals.h>
 #  define char16_t wchar_t
 #elif defined(__cplusplus) && \
       (__cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__))
    /* C++11 has a builtin char16_t type. */
 #  define MOZ_UTF16_HELPER(s) u##s
+   /**
+    * This macro is used to distinguish when char16_t would be a distinct
+    * typedef from wchar_t.
+    */
+#  define MOZ_CHAR16_IS_NOT_WCHAR
 #else
 #  error "Char16.h requires C++11 (or something like it) for UTF-16 support."
 #endif
 
 /*
  * Macro arguments used in concatenation or stringification won't be expanded.
  * Therefore, in order for |MOZ_UTF16(FOO)| to work as expected (which is to
  * expand |FOO| before doing whatever |MOZ_UTF16| needs to do to it) a helper
  * macro, |MOZ_UTF16_HELPER| needs to be inserted in between to allow the macro
  * argument to expand. See "3.10.6 Separate Expansion of Macro Arguments" of the
  * CPP manual for a more accurate and precise explanation.
  */
 #define MOZ_UTF16(s) MOZ_UTF16_HELPER(s)
 
 static_assert(sizeof(char16_t) == 2, "Is char16_t type 16 bits?");
+static_assert(char16_t(-1) > char16_t(0), "Is char16_t type unsigned?");
 static_assert(sizeof(MOZ_UTF16('A')) == 2, "Is char literal 16 bits?");
 static_assert(sizeof(MOZ_UTF16("")[0]) == 2, "Is string char 16 bits?");
 
 #endif /* mozilla_Char16_h */
--- a/mfbt/TypeTraits.h
+++ b/mfbt/TypeTraits.h
@@ -58,16 +58,19 @@ template<> struct IsIntegralHelper<unsig
 template<> struct IsIntegralHelper<int>                : TrueType {};
 template<> struct IsIntegralHelper<unsigned int>       : TrueType {};
 template<> struct IsIntegralHelper<long>               : TrueType {};
 template<> struct IsIntegralHelper<unsigned long>      : TrueType {};
 template<> struct IsIntegralHelper<long long>          : TrueType {};
 template<> struct IsIntegralHelper<unsigned long long> : TrueType {};
 template<> struct IsIntegralHelper<bool>               : TrueType {};
 template<> struct IsIntegralHelper<wchar_t>            : TrueType {};
+#ifdef MOZ_CHAR16_IS_NOT_WCHAR
+template<> struct IsIntegralHelper<char16_t>           : TrueType {};
+#endif
 
 } /* namespace detail */
 
 /**
  * IsIntegral determines whether a type is an integral type.
  *
  * mozilla::IsIntegral<int>::value is true;
  * mozilla::IsIntegral<unsigned short>::value is true;
@@ -213,16 +216,19 @@ template<> struct IsPod<unsigned int>   
 template<> struct IsPod<long>               : TrueType {};
 template<> struct IsPod<unsigned long>      : TrueType {};
 template<> struct IsPod<long long>          : TrueType {};
 template<> struct IsPod<unsigned long long> : TrueType {};
 template<> struct IsPod<bool>               : TrueType {};
 template<> struct IsPod<float>              : TrueType {};
 template<> struct IsPod<double>             : TrueType {};
 template<> struct IsPod<wchar_t>            : TrueType {};
+#ifdef MOZ_CHAR16_IS_NOT_WCHAR
+template<> struct IsPod<char16_t>           : TrueType {};
+#endif
 template<typename T> struct IsPod<T*>       : TrueType {};
 
 namespace detail {
 
 template<typename T, bool = IsFloatingPoint<T>::value>
 struct IsSignedHelper;
 
 template<typename T>