1 From 4fd9d6ce9a951e66e727b296138f22cd05479de1 Mon Sep 17 00:00:00 2001
2 From: Fredrik Roubert <roubert@google.com>
3 Date: Tue, 18 Apr 2023 23:39:28 +0200
4 Subject: [PATCH] ICU-22356 Use ConstChar16Ptr to safely cast from UChar* to
7 This is necessary for this header file to be usable by clients that
8 define UCHAR_TYPE as a type not compatible with char16_t, eg. uint16_t.
10 icu4c/source/common/unicode/ures.h | 9 +++++----
11 icu4c/source/test/intltest/Makefile.in | 2 +-
12 icu4c/source/test/intltest/intltest.vcxproj | 1 +
13 icu4c/source/test/intltest/intltest.vcxproj.filters | 3 +++
14 icu4c/source/test/intltest/uchar_type_build_test.cpp | 7 +++++++
15 5 files changed, 17 insertions(+), 5 deletions(-)
16 create mode 100644 icu4c/source/test/intltest/uchar_type_build_test.cpp
18 diff --git a/icu4c/source/common/unicode/ures.h b/icu4c/source/common/unicode/ures.h
19 index cc25b6e49cd..babc01d426a 100644
20 --- a/icu4c/source/common/unicode/ures.h
21 +++ b/icu4c/source/common/unicode/ures.h
26 +#include "unicode/char16ptr.h"
27 #include "unicode/utypes.h"
28 #include "unicode/uloc.h"
30 @@ -812,7 +813,7 @@ inline UnicodeString
31 ures_getUnicodeString(const UResourceBundle *resB, UErrorCode* status) {
34 - const char16_t *r = ures_getString(resB, &len, status);
35 + const char16_t *r = ConstChar16Ptr(ures_getString(resB, &len, status));
36 if(U_SUCCESS(*status)) {
37 result.setTo(true, r, len);
39 @@ -837,7 +838,7 @@ inline UnicodeString
40 ures_getNextUnicodeString(UResourceBundle *resB, const char ** key, UErrorCode* status) {
43 - const char16_t* r = ures_getNextString(resB, &len, key, status);
44 + const char16_t* r = ConstChar16Ptr(ures_getNextString(resB, &len, key, status));
45 if(U_SUCCESS(*status)) {
46 result.setTo(true, r, len);
48 @@ -859,7 +860,7 @@ inline UnicodeString
49 ures_getUnicodeStringByIndex(const UResourceBundle *resB, int32_t indexS, UErrorCode* status) {
52 - const char16_t* r = ures_getStringByIndex(resB, indexS, &len, status);
53 + const char16_t* r = ConstChar16Ptr(ures_getStringByIndex(resB, indexS, &len, status));
54 if(U_SUCCESS(*status)) {
55 result.setTo(true, r, len);
57 @@ -882,7 +883,7 @@ inline UnicodeString
58 ures_getUnicodeStringByKey(const UResourceBundle *resB, const char* key, UErrorCode* status) {
61 - const char16_t* r = ures_getStringByKey(resB, key, &len, status);
62 + const char16_t* r = ConstChar16Ptr(ures_getStringByKey(resB, key, &len, status));
63 if(U_SUCCESS(*status)) {
64 result.setTo(true, r, len);
66 diff --git a/icu4c/source/test/intltest/Makefile.in b/icu4c/source/test/intltest/Makefile.in
67 index 8007d3c1880..f57f8d995f4 100644
68 --- a/icu4c/source/test/intltest/Makefile.in
69 +++ b/icu4c/source/test/intltest/Makefile.in
70 @@ -70,7 +70,7 @@ numbertest_parse.o numbertest_doubleconversion.o numbertest_skeletons.o \
71 static_unisets_test.o numfmtdatadriventest.o numbertest_range.o erarulestest.o \
72 formattedvaluetest.o formatted_string_builder_test.o numbertest_permutation.o \
73 units_data_test.o units_router_test.o units_test.o displayoptions_test.o \
75 +numbertest_simple.o uchar_type_build_test.o
77 DEPS = $(OBJECTS:.o=.d)
79 diff --git a/icu4c/source/test/intltest/intltest.vcxproj b/icu4c/source/test/intltest/intltest.vcxproj
80 index 0985ba1e808..71ce1254038 100644
81 --- a/icu4c/source/test/intltest/intltest.vcxproj
82 +++ b/icu4c/source/test/intltest/intltest.vcxproj
84 <ClCompile Include="units_data_test.cpp" />
85 <ClCompile Include="units_router_test.cpp" />
86 <ClCompile Include="units_test.cpp" />
87 + <ClCompile Include="uchar_type_build_test.cpp" />
90 <ClInclude Include="colldata.h" />
91 diff --git a/icu4c/source/test/intltest/intltest.vcxproj.filters b/icu4c/source/test/intltest/intltest.vcxproj.filters
92 index ffe9bc1467d..5d8777c5aaf 100644
93 --- a/icu4c/source/test/intltest/intltest.vcxproj.filters
94 +++ b/icu4c/source/test/intltest/intltest.vcxproj.filters
96 <ClCompile Include="units_test.cpp">
97 <Filter>formatting</Filter>
99 + <ClCompile Include="uchar_type_build_test.cpp">
100 + <Filter>configuration</Filter>
104 <ClInclude Include="itrbbi.h">
105 diff --git a/icu4c/source/test/intltest/uchar_type_build_test.cpp b/icu4c/source/test/intltest/uchar_type_build_test.cpp
107 index 00000000000..ca9335441a3
109 +++ b/icu4c/source/test/intltest/uchar_type_build_test.cpp
111 +// © 2023 and later: Unicode, Inc. and others.
112 +// License & terms of use: http://www.unicode.org/copyright.html#License
114 +// ICU-22356 Test that client code can be built with UCHAR_TYPE redefined.
116 +#define UCHAR_TYPE uint16_t
117 +#include "unicode/ures.h"