diff --git a/icu4c/source/common/unicode/platform.h b/icu4c/source/common/unicode/platform.h index 1f44c9d1354..49ce3a86b14 100644 --- a/icu4c/source/common/unicode/platform.h +++ b/icu4c/source/common/unicode/platform.h @@ -711,9 +711,9 @@ /* * Notes: * C++11 and C11 require support for UTF-16 literals - * TODO: Fix for plain C. Doesn't work on Mac. + * Doesn't work on Mac C11 (see workaround in ptypes.h). */ -# if U_CPLUSPLUS_VERSION >= 11 || (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) +# if defined(__cplusplus) || !U_PLATFORM_IS_DARWIN_BASED # define U_HAVE_CHAR16_T 1 # else # define U_HAVE_CHAR16_T 0 diff --git a/icu4c/source/common/unicode/ptypes.h b/icu4c/source/common/unicode/ptypes.h index 7f1607eb483..270a729ccb0 100644 --- a/icu4c/source/common/unicode/ptypes.h +++ b/icu4c/source/common/unicode/ptypes.h @@ -51,4 +51,16 @@ #include +// C++11 and C11 both specify that the data type char16_t should exist, C++11 +// as a keyword and C11 as a typedef in the uchar.h header file, but not all +// implementations (looking at you, Apple, spring 2024) actually do this, so +// ICU4C must detect and deal with that. +#if !defined(__cplusplus) && !defined(U_IN_DOXYGEN) +# if U_HAVE_CHAR16_T +# include +# else + typedef uint16_t char16_t; +# endif +#endif + #endif /* _PTYPES_H */ diff --git a/icu4c/source/common/unicode/umachine.h b/icu4c/source/common/unicode/umachine.h index 545abef5956..c501b253b01 100644 --- a/icu4c/source/common/unicode/umachine.h +++ b/icu4c/source/common/unicode/umachine.h @@ -370,22 +370,14 @@ typedef int8_t UBool; #if 1 // #if 1 is normal. UChar defaults to char16_t in C++. // For configuration testing of UChar=uint16_t temporarily change this to #if 0. - // The intltest Makefile #defines UCHAR_TYPE=char16_t, - // so we only #define it to uint16_t if it is undefined so far. -#elif !defined(UCHAR_TYPE) +#else # define UCHAR_TYPE uint16_t #endif -#if defined(U_COMBINED_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION) || \ - defined(U_I18N_IMPLEMENTATION) || defined(U_IO_IMPLEMENTATION) - // Inside the ICU library code, never configurable. +#if defined(U_ALL_IMPLEMENTATION) || !defined(UCHAR_TYPE) typedef char16_t UChar; -#elif defined(UCHAR_TYPE) - typedef UCHAR_TYPE UChar; -#elif U_CPLUSPLUS_VERSION != 0 - typedef char16_t UChar; // C++ #else - typedef uint16_t UChar; // C + typedef UCHAR_TYPE UChar; #endif /** diff --git a/icu4c/source/icudefs.mk.in b/icu4c/source/icudefs.mk.in index 2c358167a83..61b537097e5 100644 --- a/icu4c/source/icudefs.mk.in +++ b/icu4c/source/icudefs.mk.in @@ -129,7 +129,7 @@ SED = @SED@ # configure prevents user defined DEFS, and configure's DEFS is not needed # So we ignore the DEFS that comes from configure # U_ATTRIBUTE_DEPRECATED is defined to hide warnings about deprecated API warnings. -DEFS = -DU_ATTRIBUTE_DEPRECATED= +DEFS = -DU_ALL_IMPLEMENTATION -DU_ATTRIBUTE_DEPRECATED= # CFLAGS is for C only flags CFLAGS = @CFLAGS@ # CXXFLAGS is for C++ only flags diff --git a/icu4c/source/test/intltest/Makefile.in b/icu4c/source/test/intltest/Makefile.in index af3493def5c..319c1e28c9f 100644 --- a/icu4c/source/test/intltest/Makefile.in +++ b/icu4c/source/test/intltest/Makefile.in @@ -35,7 +35,7 @@ BUILDDIR := $(BUILDDIR:test\\intltest/../../=) BUILDDIR := $(BUILDDIR:TEST\\INTLTEST/../../=) CPPFLAGS += -I$(srcdir) -I$(top_srcdir)/common -I$(top_srcdir)/i18n -I$(top_srcdir)/tools/toolutil -I$(top_srcdir)/tools/ctestfw -CPPFLAGS += -DUNISTR_FROM_CHAR_EXPLICIT= -DUNISTR_FROM_STRING_EXPLICIT= -DUCHAR_TYPE=char16_t +CPPFLAGS += -DUNISTR_FROM_CHAR_EXPLICIT= -DUNISTR_FROM_STRING_EXPLICIT= ifdef QNX_TARGET DEFS += -D'U_TOPSRCDIR="/var/icu_tests"' -D'U_TOPBUILDDIR="/var/icu_tests/"' else diff --git a/icu4c/source/test/intltest/uchar_type_build_test.cpp b/icu4c/source/test/intltest/uchar_type_build_test.cpp index ca9335441a3..f44ff01ebc7 100644 --- a/icu4c/source/test/intltest/uchar_type_build_test.cpp +++ b/icu4c/source/test/intltest/uchar_type_build_test.cpp @@ -2,6 +2,7 @@ // License & terms of use: http://www.unicode.org/copyright.html#License // ICU-22356 Test that client code can be built with UCHAR_TYPE redefined. +#undef U_ALL_IMPLEMENTATION #undef UCHAR_TYPE #define UCHAR_TYPE uint16_t #include "unicode/ures.h"