]> granicus.if.org Git - icu/commitdiff
ICU-9728 do not automatically define UChar=char16_t because that makes C++ APIs incom...
authorMarkus Scherer <markus.icu@gmail.com>
Fri, 9 Nov 2012 17:57:46 +0000 (17:57 +0000)
committerMarkus Scherer <markus.icu@gmail.com>
Fri, 9 Nov 2012 17:57:46 +0000 (17:57 +0000)
X-SVN-Rev: 32780

icu4c/source/common/unicode/platform.h
icu4c/source/common/unicode/umachine.h
icu4c/source/common/unicode/ustring.h
icu4c/source/test/intltest/strtest.cpp

index 94769d63f9a29fae0f1f77c88e6346b4d46fe33d..46b8d5c8fde8f2459e8de27ba7f1cd6467e2ba47 100644 (file)
      * does not support u"abc" string literals.
      * gcc 4.4 defines the __CHAR16_TYPE__ macro to a usable type but
      * does not support u"abc" string literals.
-     * C++11 requires support for UTF-16 literals
+     * C++11 and C11 require support for UTF-16 literals
      */
-#   if (defined(__cplusplus) && __cplusplus >= 201103L)
+#   if (defined(__cplusplus) && __cplusplus >= 201103L) || (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L)
 #       define U_HAVE_CHAR16_T 1
 #   else
 #       define U_HAVE_CHAR16_T 0
index 6dd6a8e58897e0812d1b42c5983669453b475ea3..d1102f4936527c92b13bcaf84c8aedca6e7ff757 100644 (file)
@@ -256,7 +256,7 @@ typedef int8_t UBool;
 
 /**
  * \var UChar
- * Define UChar to be char16_t, if available,
+ * Define UChar to be UCHAR_TYPE, if that is #defined (for example, to char16_t),
  * or wchar_t if that is 16 bits wide; always assumed to be unsigned.
  * If neither is available, then define UChar to be uint16_t.
  *
@@ -266,10 +266,10 @@ typedef int8_t UBool;
  *
  * @stable ICU 4.4
  */
-
-/* Define UChar to be compatible with char16_t or wchar_t if possible. */
-#if U_HAVE_CHAR16_T
-    typedef char16_t UChar;
+#if defined(UCHAR_TYPE)
+    typedef UCHAR_TYPE UChar;
+/* Not #elif U_HAVE_CHAR16_T -- because that is type-incompatible with pre-C++11 callers
+    typedef char16_t UChar;  */
 #elif U_SIZEOF_WCHAR_T==2
     typedef wchar_t UChar;
 #elif defined(__CHAR16_TYPE__)
index c57743158585d6068a4c0b978c1076f15dc0c892..d2ea31c6747f8f1c1eb0370e2843c3f64498b0f1 100644 (file)
@@ -939,7 +939,7 @@ u_memrchr32(const UChar *s, UChar32 c, int32_t count);
  * @stable ICU 2.0
  */
 #if defined(U_DECLARE_UTF16)
-#   define U_STRING_DECL(var, cs, length) static const UChar var[(length)+1]=U_DECLARE_UTF16(cs)
+#   define U_STRING_DECL(var, cs, length) static const UChar *var=(const UChar *)U_DECLARE_UTF16(cs)
     /**@stable ICU 2.0 */
 #   define U_STRING_INIT(var, cs, length)
 #elif U_SIZEOF_WCHAR_T==U_SIZEOF_UCHAR && (U_CHARSET_FAMILY==U_ASCII_FAMILY || (U_SIZEOF_UCHAR == 2 && defined(U_WCHAR_IS_UTF16)))
index 1f7c81d4ae56694445e576f5d418bb96cdaf5e00..2081454d5fead6ffbeaea7aa021acea079485c31 100644 (file)
@@ -1,6 +1,6 @@
 /********************************************************************
  * COPYRIGHT: 
- * Copyright (c) 1997-2011, International Business Machines Corporation and
+ * Copyright (c) 1997-2012, International Business Machines Corporation and
  * others. All Rights Reserved.
  ********************************************************************/
 /*   file name:  strtest.cpp
@@ -94,7 +94,7 @@ U_STRING_DECL(ustringVar, "aZ0 -", 5);
 void
 StringTest::Test_U_STRING() {
     U_STRING_INIT(ustringVar, "aZ0 -", 5);
-    if( sizeof(ustringVar)/sizeof(*ustringVar)!=6 ||
+    if( u_strlen(ustringVar)!=5 ||
         ustringVar[0]!=0x61 ||
         ustringVar[1]!=0x5a ||
         ustringVar[2]!=0x30 ||