diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt --- a/libcxx/include/CMakeLists.txt +++ b/libcxx/include/CMakeLists.txt @@ -267,6 +267,7 @@ ctgmath ctime ctype.h + cuchar cwchar cwctype deque @@ -362,6 +363,7 @@ type_traits typeindex typeinfo + uchar.h unordered_map unordered_set utility diff --git a/libcxx/include/cuchar b/libcxx/include/cuchar new file mode 100644 --- /dev/null +++ b/libcxx/include/cuchar @@ -0,0 +1,56 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_CUCHAR +#define _LIBCPP_CUCHAR + +/* + cuchar synopsis // since C++11 + +Macros: + + __STDC_UTF_16__ + __STDC_UTF_32__ + +namespace std { + +Types: + + mbstate_t + size_t + +size_t mbrtoc8(char8_t* pc8, const char* s, size_t n, mbstate_t* ps); // since C++20 +size_t c8rtomb(char* s, char8_t c8, mbstate_t* ps); // since C++20 +size_t mbrtoc16(char16_t* pc16, const char* s, size_t n, mbstate_t* ps); +size_t c16rtomb(char* s, char16_t c16, mbstate_t* ps); +size_t mbrtoc32(char32_t* pc32, const char* s, size_t n, mbstate_t* ps); +size_t c32rtomb(char* s, char32_t c32, mbstate_t* ps); + +} // std + +*/ + +#include <__config> +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD +using ::mbstate_t _LIBCPP_USING_IF_EXISTS; +using ::size_t _LIBCPP_USING_IF_EXISTS; + +using ::mbrtoc16 _LIBCPP_USING_IF_EXISTS; +using ::c16rtomb _LIBCPP_USING_IF_EXISTS; +using ::mbrtoc32 _LIBCPP_USING_IF_EXISTS; +using ::c32rtomb _LIBCPP_USING_IF_EXISTS; +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_CUCHAR diff --git a/libcxx/include/module.modulemap b/libcxx/include/module.modulemap --- a/libcxx/include/module.modulemap +++ b/libcxx/include/module.modulemap @@ -78,7 +78,10 @@ header "string.h" export * } - // FIXME: is missing. + module uchar_h { + header "uchar.h" + export * + } // provided by C library. module wchar_h { // 's __need_* macros require textual inclusion. @@ -201,7 +204,10 @@ header "ctime" export * } - // FIXME: is missing. + module cuchar { + header "cuchar" + export * + } module cwchar { header "cwchar" export depr.stdio_h diff --git a/libcxx/include/uchar.h b/libcxx/include/uchar.h new file mode 100644 --- /dev/null +++ b/libcxx/include/uchar.h @@ -0,0 +1,41 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_UCHAR_H +#define _LIBCPP_UCHAR_H + +/* + uchar.h synopsis // since C++11 + +Macros: + + __STDC_UTF_16__ + __STDC_UTF_32__ + +Types: + + mbstate_t + size_t + +size_t mbrtoc16(char16_t* pc16, const char* s, size_t n, mbstate_t* ps); +size_t c16rtomb(char* s, char16_t c16, mbstate_t* ps); +size_t mbrtoc32(char32_t* pc32, const char* s, size_t n, mbstate_t* ps); +size_t c32rtomb(char* s, char32_t c32, mbstate_t* ps); + +*/ + +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#include_next + +#endif // _LIBCPP_UCHAR_H diff --git a/libcxx/test/libcxx/double_include.sh.cpp b/libcxx/test/libcxx/double_include.sh.cpp --- a/libcxx/test/libcxx/double_include.sh.cpp +++ b/libcxx/test/libcxx/double_include.sh.cpp @@ -80,6 +80,9 @@ #include #include #include +#if __cplusplus >= 201103L +# include +#endif #include #include #include @@ -186,6 +189,9 @@ #include #include #include +#if __cplusplus >= 201103L +# include +#endif #include #include #include diff --git a/libcxx/test/libcxx/min_max_macros.compile.pass.cpp b/libcxx/test/libcxx/min_max_macros.compile.pass.cpp --- a/libcxx/test/libcxx/min_max_macros.compile.pass.cpp +++ b/libcxx/test/libcxx/min_max_macros.compile.pass.cpp @@ -116,6 +116,10 @@ TEST_MACROS(); #include TEST_MACROS(); +#if __cplusplus >= 201103L +# include +TEST_MACROS(); +#endif #include TEST_MACROS(); #include @@ -290,6 +294,10 @@ TEST_MACROS(); #include TEST_MACROS(); +#if __cplusplus >= 201103L +# include +TEST_MACROS(); +#endif #include TEST_MACROS(); #include diff --git a/libcxx/test/libcxx/no_assert_include.compile.pass.cpp b/libcxx/test/libcxx/no_assert_include.compile.pass.cpp --- a/libcxx/test/libcxx/no_assert_include.compile.pass.cpp +++ b/libcxx/test/libcxx/no_assert_include.compile.pass.cpp @@ -73,6 +73,9 @@ #include #include #include +#if __cplusplus >= 201103L +# include +#endif #include #include #include @@ -179,6 +182,9 @@ #include #include #include +#if __cplusplus >= 201103L +# include +#endif #include #include #include diff --git a/libcxx/test/libcxx/strings/c.strings/version_cuchar.pass.cpp b/libcxx/test/libcxx/strings/c.strings/version_cuchar.pass.cpp --- a/libcxx/test/libcxx/strings/c.strings/version_cuchar.pass.cpp +++ b/libcxx/test/libcxx/strings/c.strings/version_cuchar.pass.cpp @@ -5,13 +5,6 @@ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// -// -// XFAIL: * - -// Skip this test on windows. If built on top of the MSVC runtime, the -// header actually does exist (although not provided by us). -// This should be removed once D97870 has landed. -// UNSUPPORTED: windows // diff --git a/libcxx/test/std/depr/depr.c.headers/uchar_h.compile.pass.cpp b/libcxx/test/std/depr/depr.c.headers/uchar_h.compile.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/depr/depr.c.headers/uchar_h.compile.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03 + +// XFAIL: suse-linux-enterprise-server-11 +// XFAIL: netbsd + +// The macOS SDK doesn't contain yet, so these tests fail. +// XFAIL: darwin + +// + +#include + +#include "test_macros.h" + +// __STDC_UTF_16__ may or may not be defined by the C standard library +// __STDC_UTF_32__ may or may not be defined by the C standard library + +ASSERT_SAME_TYPE(size_t, decltype(mbrtoc16((char16_t*)0, (const char*)0, size_t{}, (mbstate_t*)0))); +ASSERT_SAME_TYPE(size_t, decltype(c16rtomb((char*)0, char16_t{}, (mbstate_t*)0))); + +ASSERT_SAME_TYPE(size_t, decltype(mbrtoc32((char32_t*)0, (const char*)0, size_t{}, (mbstate_t*)0))); +ASSERT_SAME_TYPE(size_t, decltype(c16rtomb((char*)0, char32_t{}, (mbstate_t*)0))); diff --git a/libcxx/test/std/depr/depr.c.headers/uchar_h.pass.cpp b/libcxx/test/std/depr/depr.c.headers/uchar_h.pass.cpp deleted file mode 100644 --- a/libcxx/test/std/depr/depr.c.headers/uchar_h.pass.cpp +++ /dev/null @@ -1,21 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -// -// XFAIL: suse-linux-enterprise-server-11 -// XFAIL: darwin -// XFAIL: netbsd - -// - -#include - -int main(int, char**) -{ - - return 0; -} diff --git a/libcxx/test/std/strings/c.strings/cuchar.compile.pass.cpp b/libcxx/test/std/strings/c.strings/cuchar.compile.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/strings/c.strings/cuchar.compile.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03 + +// The macOS SDK doesn't contain yet, so these tests fail. +// XFAIL: darwin + +// + +#include + +#include "test_macros.h" + +// __STDC_UTF_16__ may or may not be defined by the C standard library +// __STDC_UTF_32__ may or may not be defined by the C standard library + +#if defined(__cpp_lib_char8_t) && __cpp_lib_char8_t >= 201811L +#if !defined(_LIBCPP_VERSION) // TODO: implement this in libc++ +ASSERT_SAME_TYPE(size_t, decltype(std::mbrtoc8((char8_t*)0, (char const*)0, size_t(), (mbstate_t*)0))); +ASSERT_SAME_TYPE(size_t, decltype(std::c8rtomb((char*)0, char8_t{}, (mbstate_t*)0))); +#endif +#endif + +ASSERT_SAME_TYPE(size_t, decltype(std::mbrtoc16((char16_t*)0, (const char*)0, size_t{}, (mbstate_t*)0))); +ASSERT_SAME_TYPE(size_t, decltype(std::c16rtomb((char*)0, char16_t{}, (mbstate_t*)0))); + +ASSERT_SAME_TYPE(size_t, decltype(std::mbrtoc32((char32_t*)0, (const char*)0, size_t{}, (mbstate_t*)0))); +ASSERT_SAME_TYPE(size_t, decltype(std::c16rtomb((char*)0, char32_t{}, (mbstate_t*)0))); diff --git a/libcxx/test/std/strings/c.strings/cuchar.pass.cpp b/libcxx/test/std/strings/c.strings/cuchar.pass.cpp deleted file mode 100644 --- a/libcxx/test/std/strings/c.strings/cuchar.pass.cpp +++ /dev/null @@ -1,26 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -// -// XFAIL: libc++ - -// Skip this test on windows. If built on top of the MSVC runtime, the -// header actually does exist (although not provided by us). -// This should be removed once D97870 has landed. -// UNSUPPORTED: windows - -// - -#include - -#include "test_macros.h" - -int main(int, char**) -{ - - return 0; -} diff --git a/libcxx/utils/generate_header_inclusion_tests.py b/libcxx/utils/generate_header_inclusion_tests.py --- a/libcxx/utils/generate_header_inclusion_tests.py +++ b/libcxx/utils/generate_header_inclusion_tests.py @@ -67,6 +67,7 @@ "compare": "20", "concepts": "20", "coroutine": "20", + "cuchar": "11", "filesystem": "17", "initializer_list": "11", "optional": "17", @@ -76,6 +77,7 @@ "system_error": "11", "thread": "11", "tuple": "11", + "uchar.h": "11", "unordered_map": "11", "unordered_set": "11", "variant": "17", diff --git a/libcxx/utils/generate_header_tests.py b/libcxx/utils/generate_header_tests.py --- a/libcxx/utils/generate_header_tests.py +++ b/libcxx/utils/generate_header_tests.py @@ -50,6 +50,9 @@ "experimental/coroutine": ["if defined(__cpp_coroutines)"], "experimental/regex": ["ifndef _LIBCPP_HAS_NO_LOCALIZATION"], + + "cuchar": ["if __cplusplus >= 201103L"], + "uchar.h": ["if __cplusplus >= 201103L"], } allowed_extensions = ['', '.h']