Bug 957358 - Restrict everything in Char16.h to C++; r=jcranmer

This commit is contained in:
Ehsan Akhgari 2014-01-12 14:55:02 -05:00
parent 5723e1696e
commit 00d0989573

View File

@ -9,11 +9,12 @@
#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
@ -23,8 +24,7 @@
* 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,
@ -32,14 +32,9 @@
*/
# 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
/**
@ -50,20 +45,6 @@
# 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
@ -178,12 +159,11 @@ typedef const char16_t* char16ptr_t;
*/
#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 */