Bug 957358 - Restrict everything in Char16.h to C++; r=jcranmer
authorEhsan Akhgari <ehsan@mozilla.com>
Sun, 12 Jan 2014 14:55:02 -0500
changeset 179060 6a9730f94bae96bc7ab3fc1b7b74e2922fbd9f60
parent 179059 2c474a82e2b0be156ec829fd367db86436dbfe2c
child 179061 b8d91785f387ca523ff084599b59bec62c410069
push id3343
push userffxbld
push dateMon, 17 Mar 2014 21:55:32 +0000
treeherdermozilla-beta@2f7d3415f79f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjcranmer
bugs957358
milestone29.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 957358 - Restrict everything in Char16.h to C++; r=jcranmer
mfbt/Char16.h
--- a/mfbt/Char16.h
+++ b/mfbt/Char16.h
@@ -4,71 +4,52 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* Implements a UTF-16 character type. */
 
 #ifndef mozilla_Char16_h
 #define mozilla_Char16_h
 
+#ifdef __cplusplus
+
 /*
- * C11 and C++11 introduce a char16_t type and support for UTF-16 string and
- * character literals. C++11's char16_t is a distinct builtin type. C11's
- * char16_t is a typedef for uint_least16_t. Technically, char16_t is a 16-bit
- * code unit of a Unicode code point, not a "character".
+ * 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
    /*
     * 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 and to unsigned short for
-    * C code.
+    * 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
-#  ifdef __cplusplus
-     typedef wchar_t char16_t;
-#  else
-     typedef unsigned short char16_t;
-#  endif
+   typedef wchar_t char16_t;
    typedef unsigned int char32_t;
-#elif defined(__cplusplus) && \
-      (__cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__))
+#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
-#elif !defined(__cplusplus)
-#  if defined(WIN32)
-#    include <yvals.h>
-     typedef wchar_t char16_t;
-#  else
-     /**
-      * We can't use the stdint.h uint16_t type here because including
-      * stdint.h will break building some of our C libraries, such as
-      * sqlite.
-      */
-     typedef unsigned short char16_t;
-#  endif
-#else
-#  error "Char16.h requires C++11 (or something like it) for UTF-16 support."
 #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.
@@ -173,17 +154,16 @@ typedef const char16_t* char16ptr_t;
  * 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)
 
-#if defined(__cplusplus) && \
-    (__cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__))
 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
 
 #endif /* mozilla_Char16_h */