Bug 826144 - Add MOZ_UTF16_HELPER() intermediary macro to handle UTF-16 stringification and concatenation correctly. r=waldo
authorChris Peterson <cpeterson@mozilla.com>
Wed, 02 Jan 2013 14:49:09 -0800
changeset 126750 5d05c702079709c311ad042edc47666143cd26d1
parent 126749 e0ecff0cf5eee611cc1dc7669051af3ce839897e
child 126751 79b2064c1a9909f33dd547ab56835fd79cfe343d
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswaldo
bugs826144
milestone20.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 826144 - Add MOZ_UTF16_HELPER() intermediary macro to handle UTF-16 stringification and concatenation correctly. r=waldo
mfbt/Char16.h
--- a/mfbt/Char16.h
+++ b/mfbt/Char16.h
@@ -23,24 +23,34 @@
 #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 our
     * char16_t as a macro to override yval.h's typedef of the same name.
     */
-#  define MOZ_UTF16(s) L##s
+#  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(s) u##s
+#  define MOZ_UTF16_HELPER(s) u##s
 #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)
+
 MOZ_STATIC_ASSERT(sizeof(char16_t) == 2, "Is char16_t type 16 bits?");
 MOZ_STATIC_ASSERT(sizeof(MOZ_UTF16('A')) == 2, "Is char literal 16 bits?");
 MOZ_STATIC_ASSERT(sizeof(MOZ_UTF16("")[0]) == 2, "Is string char 16 bits?");
 
 #endif /* mozilla_Char16_h_ */