Bug 1119075: Use standard unicode literals with VS2015 and later, r=waldo
authorBrian Smith <brian@briansmith.org>
Wed, 07 Jan 2015 13:49:32 -0800
changeset 223495 1aac5e49e4bd20f885263c6d12b8195b1e53281d
parent 223494 5426d449fa95114a750cc5c6439bcf60eaa7b37e
child 223496 f7d82a8a8e94a74ff4afd522602a39120658e44e
push id28095
push usercbook@mozilla.com
push dateTue, 13 Jan 2015 13:24:48 +0000
treeherdermozilla-central@a5700bec72e1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswaldo
bugs1119075
milestone38.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 1119075: Use standard unicode literals with VS2015 and later, r=waldo
mfbt/Char16.h
--- a/mfbt/Char16.h
+++ b/mfbt/Char16.h
@@ -12,24 +12,25 @@
 #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".
  */
 
-#ifdef _MSC_VER
+#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. 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.
+    * 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;
@@ -46,23 +47,24 @@ typedef unsigned int char32_t;
 #    define MOZ_USE_CHAR16_WRAPPER
 #  endif
 #endif
 
 #ifdef MOZ_USE_CHAR16_WRAPPER
 # include <string>
   /**
    * 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, but GCC
-   * follows 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 |typedef const char16_t* char16ptr_t|. Here, we want to make
-   * the class as similar to this typedef, including providing some casts that
-   * are allowed by the typedef.
+   * 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
+   * |typedef const char16_t* char16ptr_t|. Here, we want to make the class as
+   * similar to this typedef, including providing some casts that are allowed
+   * by the typedef.
    */
 class char16ptr_t
 {
 private:
   const char16_t* mPtr;
   static_assert(sizeof(char16_t) == sizeof(wchar_t),
                 "char16_t and wchar_t sizes differ");