diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt --- a/libcxx/include/CMakeLists.txt +++ b/libcxx/include/CMakeLists.txt @@ -97,6 +97,9 @@ __bits __bsd_locale_defaults.h __bsd_locale_fallbacks.h + __charconv/chars_format.h + __charconv/from_chars_result.h + __charconv/to_chars_result.h __compare/common_comparison_category.h __compare/compare_three_way_result.h __compare/ordering.h diff --git a/libcxx/include/__charconv/chars_format.h b/libcxx/include/__charconv/chars_format.h new file mode 100644 --- /dev/null +++ b/libcxx/include/__charconv/chars_format.h @@ -0,0 +1,77 @@ +// -*- 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___CHARCONV_CHARS_FORMAT_H +#define _LIBCPP___CHARCONV_CHARS_FORMAT_H + +#include <__config> +#include <__utility/to_underlying.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#ifndef _LIBCPP_CXX03_LANG + +enum class _LIBCPP_ENUM_VIS chars_format +{ + scientific = 0x1, + fixed = 0x2, + hex = 0x4, + general = fixed | scientific +}; + +inline _LIBCPP_INLINE_VISIBILITY constexpr chars_format +operator~(chars_format __x) { + return chars_format(~_VSTD::__to_underlying(__x)); +} + +inline _LIBCPP_INLINE_VISIBILITY constexpr chars_format +operator&(chars_format __x, chars_format __y) { + return chars_format(_VSTD::__to_underlying(__x) & + _VSTD::__to_underlying(__y)); +} + +inline _LIBCPP_INLINE_VISIBILITY constexpr chars_format +operator|(chars_format __x, chars_format __y) { + return chars_format(_VSTD::__to_underlying(__x) | + _VSTD::__to_underlying(__y)); +} + +inline _LIBCPP_INLINE_VISIBILITY constexpr chars_format +operator^(chars_format __x, chars_format __y) { + return chars_format(_VSTD::__to_underlying(__x) ^ + _VSTD::__to_underlying(__y)); +} + +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 chars_format& +operator&=(chars_format& __x, chars_format __y) { + __x = __x & __y; + return __x; +} + +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 chars_format& +operator|=(chars_format& __x, chars_format __y) { + __x = __x | __y; + return __x; +} + +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 chars_format& +operator^=(chars_format& __x, chars_format __y) { + __x = __x ^ __y; + return __x; +} + +#endif // _LIBCPP_CXX03_LANG + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___CHARCONV_CHARS_FORMAT_H diff --git a/libcxx/include/__charconv/from_chars_result.h b/libcxx/include/__charconv/from_chars_result.h new file mode 100644 --- /dev/null +++ b/libcxx/include/__charconv/from_chars_result.h @@ -0,0 +1,34 @@ +// -*- 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___CHARCONV_FROM_CHARS_RESULT_H +#define _LIBCPP___CHARCONV_FROM_CHARS_RESULT_H + +#include <__config> +#include <__errc> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#ifndef _LIBCPP_CXX03_LANG + +struct _LIBCPP_TYPE_VIS from_chars_result +{ + const char* ptr; + errc ec; +}; + +#endif // _LIBCPP_CXX03_LANG + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___CHARCONV_FROM_CHARS_RESULT_H diff --git a/libcxx/include/__charconv/to_chars_result.h b/libcxx/include/__charconv/to_chars_result.h new file mode 100644 --- /dev/null +++ b/libcxx/include/__charconv/to_chars_result.h @@ -0,0 +1,34 @@ +// -*- 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___CHARCONV_TO_CHARS_RESULT_H +#define _LIBCPP___CHARCONV_TO_CHARS_RESULT_H + +#include <__config> +#include <__errc> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#ifndef _LIBCPP_CXX03_LANG + +struct _LIBCPP_TYPE_VIS to_chars_result +{ + char* ptr; + errc ec; +}; + +#endif // _LIBCPP_CXX03_LANG + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___CHARCONV_TO_CHARS_RESULT_H diff --git a/libcxx/include/charconv b/libcxx/include/charconv --- a/libcxx/include/charconv +++ b/libcxx/include/charconv @@ -75,9 +75,11 @@ #include <__availability> #include <__bits> +#include <__charconv/chars_format.h> +#include <__charconv/from_chars_result.h> +#include <__charconv/to_chars_result.h> #include <__config> #include <__errc> -#include <__utility/to_underlying.h> #include // for log2f #include #include // for _LIBCPP_UNREACHABLE @@ -103,67 +105,6 @@ #ifndef _LIBCPP_CXX03_LANG -enum class _LIBCPP_ENUM_VIS chars_format -{ - scientific = 0x1, - fixed = 0x2, - hex = 0x4, - general = fixed | scientific -}; - -inline _LIBCPP_INLINE_VISIBILITY constexpr chars_format -operator~(chars_format __x) { - return chars_format(~_VSTD::__to_underlying(__x)); -} - -inline _LIBCPP_INLINE_VISIBILITY constexpr chars_format -operator&(chars_format __x, chars_format __y) { - return chars_format(_VSTD::__to_underlying(__x) & - _VSTD::__to_underlying(__y)); -} - -inline _LIBCPP_INLINE_VISIBILITY constexpr chars_format -operator|(chars_format __x, chars_format __y) { - return chars_format(_VSTD::__to_underlying(__x) | - _VSTD::__to_underlying(__y)); -} - -inline _LIBCPP_INLINE_VISIBILITY constexpr chars_format -operator^(chars_format __x, chars_format __y) { - return chars_format(_VSTD::__to_underlying(__x) ^ - _VSTD::__to_underlying(__y)); -} - -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 chars_format& -operator&=(chars_format& __x, chars_format __y) { - __x = __x & __y; - return __x; -} - -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 chars_format& -operator|=(chars_format& __x, chars_format __y) { - __x = __x | __y; - return __x; -} - -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 chars_format& -operator^=(chars_format& __x, chars_format __y) { - __x = __x ^ __y; - return __x; -} - -struct _LIBCPP_TYPE_VIS to_chars_result -{ - char* ptr; - errc ec; -}; - -struct _LIBCPP_TYPE_VIS from_chars_result -{ - const char* ptr; - errc ec; -}; - void to_chars(char*, char*, bool, int = 10) = delete; void from_chars(const char*, const char*, bool, int = 10) = delete; diff --git a/libcxx/include/module.modulemap b/libcxx/include/module.modulemap --- a/libcxx/include/module.modulemap +++ b/libcxx/include/module.modulemap @@ -346,6 +346,13 @@ module charconv { header "charconv" export * + + module __charconv { + module chars_format { private header "__charconv/chars_format.h" } + module from_chars_result { private header "__charconv/from_chars_result.h" } + module to_chars_result { private header "__charconv/to_chars_result.h" } + } + } module chrono { header "chrono" diff --git a/libcxx/test/libcxx/diagnostics/detail.headers/charconv/chars_format.module.verify.cpp b/libcxx/test/libcxx/diagnostics/detail.headers/charconv/chars_format.module.verify.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/libcxx/diagnostics/detail.headers/charconv/chars_format.module.verify.cpp @@ -0,0 +1,16 @@ +// -*- 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 +// +//===----------------------------------------------------------------------===// + +// REQUIRES: modules-build + +// WARNING: This test was generated by 'generate_private_header_tests.py' +// and should not be edited manually. + +// expected-error@*:* {{use of private header from outside its module: '__charconv/chars_format.h'}} +#include <__charconv/chars_format.h> diff --git a/libcxx/test/libcxx/diagnostics/detail.headers/charconv/from_chars_result.module.verify.cpp b/libcxx/test/libcxx/diagnostics/detail.headers/charconv/from_chars_result.module.verify.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/libcxx/diagnostics/detail.headers/charconv/from_chars_result.module.verify.cpp @@ -0,0 +1,16 @@ +// -*- 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 +// +//===----------------------------------------------------------------------===// + +// REQUIRES: modules-build + +// WARNING: This test was generated by 'generate_private_header_tests.py' +// and should not be edited manually. + +// expected-error@*:* {{use of private header from outside its module: '__charconv/from_chars_result.h'}} +#include <__charconv/from_chars_result.h> diff --git a/libcxx/test/libcxx/diagnostics/detail.headers/charconv/to_chars_result.module.verify.cpp b/libcxx/test/libcxx/diagnostics/detail.headers/charconv/to_chars_result.module.verify.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/libcxx/diagnostics/detail.headers/charconv/to_chars_result.module.verify.cpp @@ -0,0 +1,16 @@ +// -*- 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 +// +//===----------------------------------------------------------------------===// + +// REQUIRES: modules-build + +// WARNING: This test was generated by 'generate_private_header_tests.py' +// and should not be edited manually. + +// expected-error@*:* {{use of private header from outside its module: '__charconv/to_chars_result.h'}} +#include <__charconv/to_chars_result.h>