Bug 1277106 - Part 1: Use VS2015's real char16_t instead of aliasing wchar_t. r=Waldo
authorChris Peterson <cpeterson@mozilla.com>
Wed, 20 Jul 2016 22:01:43 -0700
changeset 346070 6e99af8e9fa468fb6d99e315a6dabc7c72822ad9
parent 346069 40a41381cbd4a49d311348b5287bbc6e6ffa9c3e
child 346071 282f7afd67657dda8e2e8568e5ac6f609311a03b
push id6389
push userraliiev@mozilla.com
push dateMon, 19 Sep 2016 13:38:22 +0000
treeherdermozilla-beta@01d67bfe6c81 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersWaldo
bugs1277106
milestone50.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 1277106 - Part 1: Use VS2015's real char16_t instead of aliasing wchar_t. r=Waldo and remove MOZ_CHAR16_IS_NOT_WCHAR #ifdefs.
mfbt/Char16.h
mfbt/HashFunctions.h
mfbt/NumericLimits.h
mfbt/TypeTraits.h
toolkit/crashreporter/nsExceptionHandler.cpp
--- a/mfbt/Char16.h
+++ b/mfbt/Char16.h
@@ -12,48 +12,18 @@
 #ifdef __cplusplus
 
 /*
  * C++11 introduces a char16_t type and support for UTF-16 string and character
  * literals. C++11's char16_t is a distinct builtin type. Technically, char16_t
  * is a 16-bit code unit of a Unicode code point, not a "character".
  */
 
-#if defined(_MSC_VER) && _MSC_VER < 1900
-   /*
-    * C++11 says char16_t is a distinct builtin type, but Windows's yvals.h
-    * typedefs char16_t as an unsigned short prior to MSVC 2015, which
-    * implemented C++11's distinct char16_t type. We would like to alias
-    * char16_t to Windows's 16-bit wchar_t so we can declare UTF-16 literals as
-    * constant expressions (and pass char16_t pointers to Windows APIs). We
-    * #define _CHAR16T here in order to prevent yvals.h from overriding our
-    * char16_t typedefs, which we set to wchar_t for C++ code.
-    *
-    * In addition, #defining _CHAR16T will prevent yvals.h from defining a
-    * char32_t type, so we have to undo that damage here and provide our own,
-    * which is identical to the yvals.h type.
-    */
-#  define MOZ_UTF16_HELPER(s) L##s
-#  define _CHAR16T
-typedef wchar_t char16_t;
-typedef unsigned int char32_t;
-#else
-   /* 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
-#  ifdef WIN32
-#    define MOZ_USE_CHAR16_WRAPPER
-#  endif
-#endif
-
-#ifdef MOZ_USE_CHAR16_WRAPPER
+#ifdef WIN32
+# define MOZ_USE_CHAR16_WRAPPER
 # include <cstdint>
   /**
    * Win32 API extensively uses wchar_t, which is represented by a separated
    * builtin type than char16_t per spec. It's not the case for MSVC prior to
    * MSVC 2015, but other compilers follow the spec. We want to mix wchar_t and
    * char16_t on Windows builds. This class is supposed to make it easier. It
    * stores char16_t const pointer, but provides implicit casts for wchar_t as
    * well. On other platforms, we simply use
@@ -217,18 +187,21 @@ typedef const char16_t* char16ptr_t;
 /*
  * 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_HELPER(s) u##s
 #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?");
+static_assert(sizeof(u'A') == 2, "Is unicode char literal 16 bits?");
+static_assert(sizeof(u""[0]) == 2, "Is unicode string char 16 bits?");
 
 #endif
 
 #endif /* mozilla_Char16_h */
--- a/mfbt/HashFunctions.h
+++ b/mfbt/HashFunctions.h
@@ -5,17 +5,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* Utilities for hashing. */
 
 /*
  * This file exports functions for hashing data down to a 32-bit value,
  * including:
  *
- *  - HashString    Hash a char* or uint16_t/wchar_t* of known or unknown
+ *  - HashString    Hash a char* or char16_t/wchar_t* of known or unknown
  *                  length.
  *
  *  - HashBytes     Hash a byte array of known length.
  *
  *  - HashGeneric   Hash one or more values.  Currently, we support uint32_t,
  *                  types which can be implicitly cast to uint32_t, data
  *                  pointers, and function pointers.
  *
@@ -255,43 +255,29 @@ HashString(const char* aStr, size_t aLen
 MOZ_MUST_USE
 inline uint32_t
 HashString(const unsigned char* aStr, size_t aLength)
 {
   return detail::HashKnownLength(aStr, aLength);
 }
 
 MOZ_MUST_USE inline uint32_t
-HashString(const uint16_t* aStr)
-{
-  return detail::HashUntilZero(aStr);
-}
-
-MOZ_MUST_USE inline uint32_t
-HashString(const uint16_t* aStr, size_t aLength)
-{
-  return detail::HashKnownLength(aStr, aLength);
-}
-
-#ifdef MOZ_CHAR16_IS_NOT_WCHAR
-MOZ_MUST_USE inline uint32_t
 HashString(const char16_t* aStr)
 {
   return detail::HashUntilZero(aStr);
 }
 
 MOZ_MUST_USE inline uint32_t
 HashString(const char16_t* aStr, size_t aLength)
 {
   return detail::HashKnownLength(aStr, aLength);
 }
-#endif
 
 /*
- * On Windows, wchar_t (char16_t) is not the same as uint16_t, even though it's
+ * On Windows, wchar_t is not the same as char16_t, even though it's
  * the same width!
  */
 #ifdef WIN32
 MOZ_MUST_USE inline uint32_t
 HashString(const wchar_t* aStr)
 {
   return detail::HashUntilZero(aStr);
 }
--- a/mfbt/NumericLimits.h
+++ b/mfbt/NumericLimits.h
@@ -22,19 +22,17 @@ namespace mozilla {
  * std::numeric_limits.  Code which does not need std::numeric_limits<char16_t>
  * should avoid using NumericLimits.
  */
 template<typename T>
 class NumericLimits : public std::numeric_limits<T>
 {
 };
 
-#ifdef MOZ_CHAR16_IS_NOT_WCHAR
 template<>
 class NumericLimits<char16_t> : public std::numeric_limits<uint16_t>
 {
   // char16_t and uint16_t numeric limits should be exactly the same.
 };
-#endif
 
 } // namespace mozilla
 
 #endif /* mozilla_NumericLimits_h */
--- a/mfbt/TypeTraits.h
+++ b/mfbt/TypeTraits.h
@@ -93,33 +93,28 @@ 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;
  * mozilla::IsIntegral<const long>::value is true;
  * mozilla::IsIntegral<int*>::value is false;
  * mozilla::IsIntegral<double>::value is false;
- *
- * Note that the behavior of IsIntegral on char16_t and char32_t is
- * unspecified.
  */
 template<typename T>
 struct IsIntegral : detail::IsIntegralHelper<typename RemoveCV<T>::Type>
 {};
 
 template<typename T, typename U>
 struct IsSame;
 
@@ -439,19 +434,17 @@ 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 {
 
 // __is_empty is a supported extension across all of our supported compilers:
 // http://llvm.org/releases/3.0/docs/ClangReleaseNotes.html
 // http://gcc.gnu.org/onlinedocs/gcc-4.4.7/gcc/Type-Traits.html#Type-Traits
 // http://msdn.microsoft.com/en-us/library/ms177194%28v=vs.100%29.aspx
--- a/toolkit/crashreporter/nsExceptionHandler.cpp
+++ b/toolkit/crashreporter/nsExceptionHandler.cpp
@@ -1155,23 +1155,21 @@ BuildTempPath(wchar_t* aBuf, size_t aBuf
   DWORD pathLen = GetTempPath(0, nullptr);
   if (pathLen == 0 || pathLen >= aBufLen) {
     return 0;
   }
 
   return GetTempPath(pathLen, aBuf);
 }
 
-#ifdef MOZ_CHAR16_IS_NOT_WCHAR
 static size_t
 BuildTempPath(char16_t* aBuf, size_t aBufLen)
 {
   return BuildTempPath(reinterpret_cast<wchar_t*>(aBuf), aBufLen);
 }
-#endif
 
 #elif defined(XP_MACOSX)
 
 static size_t
 BuildTempPath(char* aBuf, size_t aBufLen)
 {
   if (aBufLen < PATH_MAX) {
     return 0;