summaryrefslogtreecommitdiff
path: root/external/icu/icu4c-64-54558d1dd01b29c763ca12b6327108fe3ac66637.patch.2
blob: 5b9a830f6112ed50405878476dd12a630215192b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
From 54558d1dd01b29c763ca12b6327108fe3ac66637 Mon Sep 17 00:00:00 2001
From: Alon Bar-Lev <alon.barlev@gmail.com>
Date: Sat, 30 Mar 2019 09:59:46 +0300
Subject: [PATCH] ICU-20530 Re-support include under extern "C"

Up until icu-6.3 icu supported include under extern "C" under the explicit
requirements, see comment of U_NAMESPACE_BEGIN at uversion.h:

 * \def U_NAMESPACE_BEGIN
 * This is used to begin a declaration of a public ICU C++ API.
 * When not compiling for C++, it does nothing.
 * When compiling for C++, it begins an extern "C++" linkage block (to protect
 * against cases in which an external client includes ICU header files inside
 * an extern "C" linkage block).
 *
 * It also begins a versioned-ICU-namespace block.
 * @stable ICU 2.4

Recent changes were made to include C++ headers within global scope which
broke this behavior.

To keep requested behavior add two additional macros U_CXX_BEGIN, U_CXX_END to
avoid breakage of doxygen while enforcing C++ API visibility.

Signed-off-by: Alon Bar-Lev <alon.barlev@gmail.com>
---
 icu4c/source/common/unicode/char16ptr.h       |  5 +++-
 icu4c/source/common/unicode/localpointer.h    |  2 ++
 icu4c/source/common/unicode/std_string.h      |  3 +++
 icu4c/source/common/unicode/umachine.h        | 25 +++++++++++++++++++
 icu4c/source/common/unicode/unistr.h          |  5 +++-
 icu4c/source/common/unicode/uversion.h        | 15 ++++-------
 .../i18n/unicode/numberrangeformatter.h       |  5 +++-
 icu4c/source/io/unicode/ustream.h             |  2 ++
 icu4c/source/test/hdrtst/Makefile.in          | 16 ++++++++++--
 9 files changed, 63 insertions(+), 15 deletions(-)

diff --git a/icu4c/source/common/unicode/char16ptr.h b/icu4c/source/common/unicode/char16ptr.h
index a7c5f1a0c5e..f774d7d8b21 100644
--- a/icu4c/source/common/unicode/char16ptr.h
+++ b/icu4c/source/common/unicode/char16ptr.h
@@ -7,9 +7,12 @@
 #ifndef __CHAR16PTR_H__
 #define __CHAR16PTR_H__
 
-#include <cstddef>
 #include "unicode/utypes.h"
 
+U_CXX_BEGIN
+#include <cstddef>
+U_CXX_END
+
 /**
  * \file
  * \brief C++ API: char16_t pointer wrappers with
diff --git a/icu4c/source/common/unicode/localpointer.h b/icu4c/source/common/unicode/localpointer.h
index e011688b1a5..fd26dc40e9d 100644
--- a/icu4c/source/common/unicode/localpointer.h
+++ b/icu4c/source/common/unicode/localpointer.h
@@ -42,7 +42,9 @@
 
 #if U_SHOW_CPLUSPLUS_API
 
+U_CXX_BEGIN
 #include <memory>
+U_CXX_END
 
 U_NAMESPACE_BEGIN
 
diff --git a/icu4c/source/common/unicode/std_string.h b/icu4c/source/common/unicode/std_string.h
index 729c5639950..d293e714fe0 100644
--- a/icu4c/source/common/unicode/std_string.h
+++ b/icu4c/source/common/unicode/std_string.h
@@ -32,6 +32,9 @@
 #if defined(__GLIBCXX__)
 namespace std { class type_info; }
 #endif
+
+U_CXX_BEGIN
 #include <string>
+U_CXX_END
 
 #endif  // __STD_STRING_H__
diff --git a/icu4c/source/common/unicode/umachine.h b/icu4c/source/common/unicode/umachine.h
index 0205da62eb4..6137c125df4 100644
--- a/icu4c/source/common/unicode/umachine.h
+++ b/icu4c/source/common/unicode/umachine.h
@@ -75,14 +75,39 @@
  * @stable ICU 2.4
  */
 
+/**
+ * \def U_CXX_BEGIN
+ * This is used to begin a C++ block.
+ * When not compiling for C++, it does nothing.
+ * When compiling for C++, it begins an extern "C++" linkage block (to protect
+ * against cases in which an external client includes ICU header files inside
+ * an extern "C" linkage block).
+ *
+ * @draft ICU 65
+ */
+
+/**
+ * \def U_CXX_END
+ * This is used to end a declaration of a C++ API.
+ * When not compiling for C++, it does nothing.
+ * When compiling for C++, it ends the extern "C++" block begun by
+ * U_CXX_BEGIN.
+ *
+ * @draft ICU 65
+ */
+
 #ifdef __cplusplus
 #   define U_CFUNC extern "C"
 #   define U_CDECL_BEGIN extern "C" {
 #   define U_CDECL_END   }
+#   define U_CXX_BEGIN extern "C++" {
+#   define U_CXX_END }
 #else
 #   define U_CFUNC extern
 #   define U_CDECL_BEGIN
 #   define U_CDECL_END
+#   define U_CXX_BEGIN
+#   define U_CXX_END
 #endif
 
 #ifndef U_ATTRIBUTE_DEPRECATED
diff --git a/icu4c/source/common/unicode/unistr.h b/icu4c/source/common/unicode/unistr.h
index d79168b9195..c323e33c07c 100644
--- a/icu4c/source/common/unicode/unistr.h
+++ b/icu4c/source/common/unicode/unistr.h
@@ -28,7 +28,6 @@
  * \brief C++ API: Unicode String
  */
 
-#include <cstddef>
 #include "unicode/utypes.h"
 #include "unicode/char16ptr.h"
 #include "unicode/rep.h"
@@ -36,6 +35,10 @@
 #include "unicode/stringpiece.h"
 #include "unicode/bytestream.h"
 
+U_CXX_BEGIN
+#include <cstddef>
+U_CXX_END
+
 struct UConverter;          // unicode/ucnv.h
 
 #ifndef USTRING_H
diff --git a/icu4c/source/common/unicode/uversion.h b/icu4c/source/common/unicode/uversion.h
index 4aaa8b4d606..9e6bd13734f 100644
--- a/icu4c/source/common/unicode/uversion.h
+++ b/icu4c/source/common/unicode/uversion.h
@@ -64,13 +64,10 @@ typedef uint8_t UVersionInfo[U_MAX_VERSION_LENGTH];
 
 /**
  * \def U_NAMESPACE_BEGIN
- * This is used to begin a declaration of a public ICU C++ API.
+ * This is used to begin a declaration of a public ICU C++ API within
+ * versioned-ICU-namespace block.
  * When not compiling for C++, it does nothing.
- * When compiling for C++, it begins an extern "C++" linkage block (to protect
- * against cases in which an external client includes ICU header files inside
- * an extern "C" linkage block).
  *
- * It also begins a versioned-ICU-namespace block.
  * @stable ICU 2.4
  */
 
@@ -78,10 +75,8 @@ typedef uint8_t UVersionInfo[U_MAX_VERSION_LENGTH];
  * \def U_NAMESPACE_END
  * This is used to end a declaration of a public ICU C++ API.
  * When not compiling for C++, it does nothing.
- * When compiling for C++, it ends the extern "C++" block begun by
- * U_NAMESPACE_BEGIN.
+ * It ends the versioned-ICU-namespace block begun by U_NAMESPACE_BEGIN.
  *
- * It also ends the versioned-ICU-namespace block begun by U_NAMESPACE_BEGIN.
  * @stable ICU 2.4
  */
 
@@ -116,8 +111,8 @@ typedef uint8_t UVersionInfo[U_MAX_VERSION_LENGTH];
         namespace icu = U_ICU_NAMESPACE;
 #   endif
 
-#   define U_NAMESPACE_BEGIN extern "C++" { namespace U_ICU_NAMESPACE {
-#   define U_NAMESPACE_END } }
+#   define U_NAMESPACE_BEGIN U_CXX_BEGIN namespace U_ICU_NAMESPACE {
+#   define U_NAMESPACE_END } U_CXX_END
 #   define U_NAMESPACE_USE using namespace U_ICU_NAMESPACE;
 #   define U_NAMESPACE_QUALIFIER U_ICU_NAMESPACE::
 
diff --git a/icu4c/source/i18n/unicode/numberrangeformatter.h b/icu4c/source/i18n/unicode/numberrangeformatter.h
index 4a386b80394..0c6eb62ae1f 100644
--- a/icu4c/source/i18n/unicode/numberrangeformatter.h
+++ b/icu4c/source/i18n/unicode/numberrangeformatter.h
@@ -5,13 +5,16 @@
 #ifndef __NUMBERRANGEFORMATTER_H__
 #define __NUMBERRANGEFORMATTER_H__
 
-#include <atomic>
 #include "unicode/appendable.h"
 #include "unicode/fieldpos.h"
 #include "unicode/formattedvalue.h"
 #include "unicode/fpositer.h"
 #include "unicode/numberformatter.h"
 
+U_CXX_BEGIN
+#include <atomic>
+U_CXX_END
+
 #ifndef U_HIDE_DRAFT_API
 
 /**
diff --git a/icu4c/source/io/unicode/ustream.h b/icu4c/source/io/unicode/ustream.h
index c10ce6a2de5..e1ec87c75d3 100644
--- a/icu4c/source/io/unicode/ustream.h
+++ b/icu4c/source/io/unicode/ustream.h
@@ -34,7 +34,9 @@
 namespace std { class type_info; } // WORKAROUND: http://llvm.org/bugs/show_bug.cgi?id=13364
 #endif
 
+U_CXX_BEGIN
 #include <iostream>
+U_CXX_END
 
 U_NAMESPACE_BEGIN
 
diff --git a/icu4c/source/test/hdrtst/Makefile.in b/icu4c/source/test/hdrtst/Makefile.in
index 55e833943d5..a485f7a80d6 100644
--- a/icu4c/source/test/hdrtst/Makefile.in
+++ b/icu4c/source/test/hdrtst/Makefile.in
@@ -53,7 +53,7 @@ E_DEP="[6/$(E_NUM)] Hide Deprecated: "
 E_INT="[7/$(E_NUM)] Hide Internal: "
 E_OBS="[8/$(E_NUM)] Hide Obsolete: "
 
-check: dtest ctest cpptest doclean drafttest deprtest internaltest obsoletetest
+check: dtest ctest cpptest cpptest_extern_c doclean drafttest deprtest internaltest obsoletetest
 ifeq ($(MAKECMDGOALS),check)
 	$(MAKE) clean
 else
@@ -74,6 +74,18 @@ cpptest:
 	done ;\
 	exit $$FAIL
 
+cpptest_extern_c:
+	@FAIL=0;for file in `ls $(prefix)/include/unicode/*.h | fgrep -v -f $(srcdir)/pfiles.txt`; do \
+	  incfile=`basename $$file .h` ; \
+	  echo "$@ unicode/$$incfile.h" ; \
+	  echo 'extern "C" {' > ht_$$incfile.cpp ; \
+	  echo '#include "'unicode/$$incfile'.h"' >> ht_$$incfile.cpp ; \
+	  echo '}' >> ht_$$incfile.cpp ; \
+	  echo 'void junk(){}' >> ht_$$incfile.cpp ; \
+          $(COMPILE.cc) -c $(cppflags) ht_$$incfile.cpp || FAIL=1 ; \
+	done ;\
+	exit $$FAIL
+
 # layout is removed
 
 dtest:
@@ -170,5 +182,5 @@ Makefile: $(srcdir)/Makefile.in  $(top_builddir)/config.status
 	cd $(top_builddir) \
 	&& CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status
 
-.PHONY:	doclean check all cpptest dtest ctest clean distclean
+.PHONY:	doclean check all cpptest cpptest_extern_c dtest ctest clean distclean