Skip to content

Commit 311ff39

Browse files
committed
[libc++] Add missing header <cuchar>
Fixes llvm-project#44216 Differential Revision: https://reviews.llvm.org/D97870
1 parent 4bbee17 commit 311ff39

15 files changed

+214
-56
lines changed

libcxx/include/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@ set(files
448448
ctgmath
449449
ctime
450450
ctype.h
451+
cuchar
451452
cwchar
452453
cwctype
453454
deque
@@ -541,6 +542,7 @@ set(files
541542
type_traits
542543
typeindex
543544
typeinfo
545+
uchar.h
544546
unordered_map
545547
unordered_set
546548
utility

libcxx/include/cuchar

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// -*- C++ -*-
2+
//===----------------------------------------------------------------------===//
3+
//
4+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5+
// See https://llvm.org/LICENSE.txt for license information.
6+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
#ifndef _LIBCPP_CUCHAR
11+
#define _LIBCPP_CUCHAR
12+
13+
/*
14+
cuchar synopsis // since C++11
15+
16+
Macros:
17+
18+
__STDC_UTF_16__
19+
__STDC_UTF_32__
20+
21+
namespace std {
22+
23+
Types:
24+
25+
mbstate_t
26+
size_t
27+
28+
size_t mbrtoc16(char16_t* pc16, const char* s, size_t n, mbstate_t* ps);
29+
size_t c16rtomb(char* s, char16_t c16, mbstate_t* ps);
30+
size_t mbrtoc32(char32_t* pc32, const char* s, size_t n, mbstate_t* ps);
31+
size_t c32rtomb(char* s, char32_t c32, mbstate_t* ps);
32+
33+
} // std
34+
35+
*/
36+
37+
#include <__config>
38+
#include <uchar.h>
39+
40+
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
41+
# pragma GCC system_header
42+
#endif
43+
44+
_LIBCPP_BEGIN_NAMESPACE_STD
45+
46+
#if !defined(_LIBCPP_CXX03_LANG)
47+
48+
using ::mbstate_t _LIBCPP_USING_IF_EXISTS;
49+
using ::size_t _LIBCPP_USING_IF_EXISTS;
50+
51+
using ::mbrtoc16 _LIBCPP_USING_IF_EXISTS;
52+
using ::c16rtomb _LIBCPP_USING_IF_EXISTS;
53+
using ::mbrtoc32 _LIBCPP_USING_IF_EXISTS;
54+
using ::c32rtomb _LIBCPP_USING_IF_EXISTS;
55+
56+
#endif // _LIBCPP_CXX03_LANG
57+
58+
_LIBCPP_END_NAMESPACE_STD
59+
60+
#endif // _LIBCPP_CUCHAR

libcxx/include/module.modulemap

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@ module std [system] {
8080
header "string.h"
8181
export *
8282
}
83-
// FIXME: <uchar.h> is missing.
83+
module uchar_h {
84+
header "uchar.h"
85+
export *
86+
}
8487
// <time.h> provided by C library.
8588
module wchar_h {
8689
// <wchar.h>'s __need_* macros require textual inclusion.
@@ -203,7 +206,10 @@ module std [system] {
203206
header "ctime"
204207
export *
205208
}
206-
// FIXME: <cuchar> is missing.
209+
module cuchar {
210+
header "cuchar"
211+
export *
212+
}
207213
module cwchar {
208214
header "cwchar"
209215
export depr.stdio_h

libcxx/include/uchar.h

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// -*- C++ -*-
2+
//===----------------------------------------------------------------------===//
3+
//
4+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5+
// See https://llvm.org/LICENSE.txt for license information.
6+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
#ifndef _LIBCPP_UCHAR_H
11+
#define _LIBCPP_UCHAR_H
12+
13+
/*
14+
uchar.h synopsis // since C++11
15+
16+
Macros:
17+
18+
__STDC_UTF_16__
19+
__STDC_UTF_32__
20+
21+
Types:
22+
23+
mbstate_t
24+
size_t
25+
26+
size_t mbrtoc16(char16_t* pc16, const char* s, size_t n, mbstate_t* ps);
27+
size_t c16rtomb(char* s, char16_t c16, mbstate_t* ps);
28+
size_t mbrtoc32(char32_t* pc32, const char* s, size_t n, mbstate_t* ps);
29+
size_t c32rtomb(char* s, char32_t c32, mbstate_t* ps);
30+
31+
*/
32+
33+
#include <__config>
34+
35+
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
36+
# pragma GCC system_header
37+
#endif
38+
39+
#if !defined(_LIBCPP_CXX03_LANG)
40+
41+
// Some platforms don't implement <uchar.h> and we don't want to give a hard
42+
// error on those platforms. When the platform doesn't provide <uchar.h>, at
43+
// least include <stddef.h> so we get the declaration for size_t.
44+
#if __has_include_next(<uchar.h>)
45+
# include_next <uchar.h>
46+
#else
47+
# include <stddef.h>
48+
#endif
49+
50+
#endif // _LIBCPP_CXX03_LANG
51+
52+
#endif // _LIBCPP_UCHAR_H

libcxx/test/libcxx/clang_tidy.sh.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
#include <ctgmath>
7575
#include <ctime>
7676
#include <ctype.h>
77+
#include <cuchar>
7778
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
7879
# include <cwchar>
7980
#endif
@@ -188,6 +189,7 @@
188189
#include <type_traits>
189190
#include <typeindex>
190191
#include <typeinfo>
192+
#include <uchar.h>
191193
#include <unordered_map>
192194
#include <unordered_set>
193195
#include <utility>

libcxx/test/libcxx/double_include.sh.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
// RUN: %{cxx} -o %t.exe %t.first.o %t.second.o %{flags} %{link_flags}
1414
// RUN: %{run}
1515

16+
// The system-provided <uchar.h> seems to be broken on AIX
17+
// XFAIL: LIBCXX-AIX-FIXME
18+
1619
// Prevent <ext/hash_map> from generating deprecated warnings for this test.
1720
#if defined(__DEPRECATED)
1821
# undef __DEPRECATED
@@ -75,6 +78,7 @@
7578
#include <ctgmath>
7679
#include <ctime>
7780
#include <ctype.h>
81+
#include <cuchar>
7882
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
7983
# include <cwchar>
8084
#endif
@@ -189,6 +193,7 @@
189193
#include <type_traits>
190194
#include <typeindex>
191195
#include <typeinfo>
196+
#include <uchar.h>
192197
#include <unordered_map>
193198
#include <unordered_set>
194199
#include <utility>

libcxx/test/libcxx/min_max_macros.compile.pass.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
// Test that headers are not tripped up by the surrounding code defining the
1010
// min() and max() macros.
1111

12+
// The system-provided <uchar.h> seems to be broken on AIX
13+
// XFAIL: LIBCXX-AIX-FIXME
14+
1215
// Prevent <ext/hash_map> from generating deprecated warnings for this test.
1316
#if defined(__DEPRECATED)
1417
# undef __DEPRECATED
@@ -114,6 +117,8 @@ TEST_MACROS();
114117
TEST_MACROS();
115118
#include <ctype.h>
116119
TEST_MACROS();
120+
#include <cuchar>
121+
TEST_MACROS();
117122
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
118123
# include <cwchar>
119124
TEST_MACROS();
@@ -296,6 +301,8 @@ TEST_MACROS();
296301
TEST_MACROS();
297302
#include <typeinfo>
298303
TEST_MACROS();
304+
#include <uchar.h>
305+
TEST_MACROS();
299306
#include <unordered_map>
300307
TEST_MACROS();
301308
#include <unordered_set>

libcxx/test/libcxx/nasty_macros.compile.pass.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
// Test that headers are not tripped up by the surrounding code defining various
1010
// alphabetic macros.
1111

12+
// The system-provided <uchar.h> seems to be broken on AIX
13+
// XFAIL: LIBCXX-AIX-FIXME
14+
1215
// Prevent <ext/hash_map> from generating deprecated warnings for this test.
1316
#if defined(__DEPRECATED)
1417
# undef __DEPRECATED
@@ -185,6 +188,7 @@
185188
#include <ctgmath>
186189
#include <ctime>
187190
#include <ctype.h>
191+
#include <cuchar>
188192
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
189193
# include <cwchar>
190194
#endif
@@ -299,6 +303,7 @@
299303
#include <type_traits>
300304
#include <typeindex>
301305
#include <typeinfo>
306+
#include <uchar.h>
302307
#include <unordered_map>
303308
#include <unordered_set>
304309
#include <utility>

libcxx/test/libcxx/no_assert_include.compile.pass.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
// Ensure that none of the standard C++ headers implicitly include cassert or
1010
// assert.h (because assert() is implemented as a macro).
1111

12+
// The system-provided <uchar.h> seems to be broken on AIX
13+
// XFAIL: LIBCXX-AIX-FIXME
14+
1215
// Prevent <ext/hash_map> from generating deprecated warnings for this test.
1316
#if defined(__DEPRECATED)
1417
# undef __DEPRECATED
@@ -70,6 +73,7 @@
7073
#include <ctgmath>
7174
#include <ctime>
7275
#include <ctype.h>
76+
#include <cuchar>
7377
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
7478
# include <cwchar>
7579
#endif
@@ -184,6 +188,7 @@
184188
#include <type_traits>
185189
#include <typeindex>
186190
#include <typeinfo>
191+
#include <uchar.h>
187192
#include <unordered_map>
188193
#include <unordered_set>
189194
#include <utility>

libcxx/test/libcxx/strings/c.strings/version_cuchar.pass.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
8-
//
9-
// XFAIL: *
108

11-
// Skip this test on windows. If built on top of the MSVC runtime, the
12-
// <cuchar> header actually does exist (although not provided by us).
13-
// This should be removed once D97870 has landed.
14-
// UNSUPPORTED: windows
9+
// UNSUPPORTED: c++03
10+
11+
// The system-provided <uchar.h> seems to be broken on AIX
12+
// XFAIL: LIBCXX-AIX-FIXME
1513

1614
// <cuchar>
1715

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// UNSUPPORTED: c++03
10+
11+
// Apple platforms don't provide <uchar.h> yet, so these tests fail.
12+
// XFAIL: target={{.+}}-apple-{{.+}}
13+
14+
// The system-provided <uchar.h> seems to be broken on AIX
15+
// XFAIL: LIBCXX-AIX-FIXME
16+
17+
// <uchar.h>
18+
19+
#include <uchar.h>
20+
21+
#include "test_macros.h"
22+
23+
// __STDC_UTF_16__ may or may not be defined by the C standard library
24+
// __STDC_UTF_32__ may or may not be defined by the C standard library
25+
26+
ASSERT_SAME_TYPE(size_t, decltype(mbrtoc16((char16_t*)0, (const char*)0, (size_t)0, (mbstate_t*)0)));
27+
ASSERT_SAME_TYPE(size_t, decltype(c16rtomb((char*)0, (char16_t)0, (mbstate_t*)0)));
28+
29+
ASSERT_SAME_TYPE(size_t, decltype(mbrtoc32((char32_t*)0, (const char*)0, (size_t)0, (mbstate_t*)0)));
30+
ASSERT_SAME_TYPE(size_t, decltype(c16rtomb((char*)0, (char32_t)0, (mbstate_t*)0)));

libcxx/test/std/depr/depr.c.headers/uchar_h.pass.cpp

Lines changed: 0 additions & 22 deletions
This file was deleted.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// UNSUPPORTED: c++03
10+
11+
// Apple platforms don't provide <uchar.h> yet, so these tests fail.
12+
// XFAIL: target={{.+}}-apple-{{.+}}
13+
14+
// The system-provided <uchar.h> seems to be broken on AIX
15+
// XFAIL: LIBCXX-AIX-FIXME
16+
17+
// <cuchar>
18+
19+
#include <cuchar>
20+
21+
#include "test_macros.h"
22+
23+
// TODO: Implement mbrtoc8 and c8rtomb, and add tests for those
24+
25+
// __STDC_UTF_16__ may or may not be defined by the C standard library
26+
// __STDC_UTF_32__ may or may not be defined by the C standard library
27+
28+
ASSERT_SAME_TYPE(size_t, decltype(std::mbrtoc16((char16_t*)0, (const char*)0, (size_t)0, (mbstate_t*)0)));
29+
ASSERT_SAME_TYPE(size_t, decltype(std::c16rtomb((char*)0, (char16_t)0, (mbstate_t*)0)));
30+
31+
ASSERT_SAME_TYPE(size_t, decltype(std::mbrtoc32((char32_t*)0, (const char*)0, (size_t)0, (mbstate_t*)0)));
32+
ASSERT_SAME_TYPE(size_t, decltype(std::c16rtomb((char*)0, (char32_t)0, (mbstate_t*)0)));

0 commit comments

Comments
 (0)