diff --git a/libcxx/docs/ReleaseNotes.rst b/libcxx/docs/ReleaseNotes.rst --- a/libcxx/docs/ReleaseNotes.rst +++ b/libcxx/docs/ReleaseNotes.rst @@ -57,7 +57,7 @@ includes are removed based on the language version used. Incidental transitive inclusions of the following headers have been removed: - - C++2b: ``bit``, ``type_traits`` + - C++2b: ``bit``, ``cstring``, ``type_traits`` Upcoming Deprecations and Removals ---------------------------------- diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt --- a/libcxx/include/CMakeLists.txt +++ b/libcxx/include/CMakeLists.txt @@ -557,6 +557,7 @@ __split_buffer __std_stream __string/char_traits.h + __string/constexpr_c_functions.h __string/extern_template_lists.h __support/android/locale_bionic.h __support/fuchsia/xlocale.h diff --git a/libcxx/include/__bit_reference b/libcxx/include/__bit_reference --- a/libcxx/include/__bit_reference +++ b/libcxx/include/__bit_reference @@ -19,7 +19,6 @@ #include <__iterator/iterator_traits.h> #include <__memory/construct_at.h> #include <__memory/pointer_traits.h> -#include #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) diff --git a/libcxx/include/__format/format_arg_store.h b/libcxx/include/__format/format_arg_store.h --- a/libcxx/include/__format/format_arg_store.h +++ b/libcxx/include/__format/format_arg_store.h @@ -20,7 +20,6 @@ #include <__format/concepts.h> #include <__format/format_arg.h> #include <__utility/forward.h> -#include #include #include #include diff --git a/libcxx/include/__string/char_traits.h b/libcxx/include/__string/char_traits.h --- a/libcxx/include/__string/char_traits.h +++ b/libcxx/include/__string/char_traits.h @@ -18,11 +18,11 @@ #include <__config> #include <__functional/hash.h> #include <__iterator/iterator_traits.h> +#include <__string/constexpr_c_functions.h> #include <__type_traits/is_constant_evaluated.h> #include #include #include -#include #include #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS diff --git a/libcxx/include/__string/constexpr_c_functions.h b/libcxx/include/__string/constexpr_c_functions.h new file mode 100644 --- /dev/null +++ b/libcxx/include/__string/constexpr_c_functions.h @@ -0,0 +1,71 @@ +//===----------------------------------------------------------------------===// +// +// 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___STRING_CONSTEXPR_C_FUNCTIONS_H +#define _LIBCPP___STRING_CONSTEXPR_C_FUNCTIONS_H + +#include <__config> +#include <__type_traits/is_constant_evaluated.h> +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 size_t __constexpr_strlen(const char* __str) { + // GCC currently doesn't support __builtin_strlen for heap-allocated memory during constant evaluation. + // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70816 +#ifdef _LIBCPP_COMPILER_GCC + if (__libcpp_is_constant_evaluated()) { + size_t __i = 0; + for (; __str[__i] != '\0'; ++__i) + ; + return __i; + } +#endif + return __builtin_strlen(__str); +} + +template +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 int +__constexpr_memcmp(const _Tp* __lhs, const _Tp* __rhs, size_t __count) { +#ifdef _LIBCPP_COMPILER_GCC + if (__libcpp_is_constant_evaluated()) { + for (; __count; --__count, ++__lhs, ++__rhs) { + if (*__lhs < *__rhs) + return -1; + if (*__rhs < *__lhs) + return 1; + } + return 0; + } +#endif + return __builtin_memcmp(__lhs, __rhs, __count); +} + +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const char* +__constexpr_char_memchr(const char* __str, int __char, size_t __count) { +#if __has_builtin(__builtin_char_memchr) + return __builtin_char_memchr(__str, __char, __count); +#else + if (!__libcpp_is_constant_evaluated()) + return static_cast(__builtin_memchr(__str, __char, __count)); + for (; __count; --__count) { + if (*__str == __char) + return __str; + ++__str; + } + return nullptr; +#endif +} + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___STRING_CONSTEXPR_C_FUNCTIONS_H diff --git a/libcxx/include/charconv b/libcxx/include/charconv --- a/libcxx/include/charconv +++ b/libcxx/include/charconv @@ -85,7 +85,6 @@ #include // for log2f #include #include -#include #include #include @@ -831,6 +830,7 @@ #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 # include +# include # include #endif diff --git a/libcxx/include/chrono b/libcxx/include/chrono --- a/libcxx/include/chrono +++ b/libcxx/include/chrono @@ -790,6 +790,7 @@ #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 # include # include +# include #endif #endif // _LIBCPP_CHRONO diff --git a/libcxx/include/cstring b/libcxx/include/cstring --- a/libcxx/include/cstring +++ b/libcxx/include/cstring @@ -100,53 +100,6 @@ using ::strerror _LIBCPP_USING_IF_EXISTS; using ::strlen _LIBCPP_USING_IF_EXISTS; -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 size_t __constexpr_strlen(const char* __str) { - // GCC currently doesn't support __builtin_strlen for heap-allocated memory during constant evaluation. - // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70816 -#ifdef _LIBCPP_COMPILER_GCC - if (__libcpp_is_constant_evaluated()) { - size_t __i = 0; - for (; __str[__i] != '\0'; ++__i) - ; - return __i; - } -#endif - return __builtin_strlen(__str); -} - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 int -__constexpr_memcmp(const _Tp* __lhs, const _Tp* __rhs, size_t __count) { -#ifdef _LIBCPP_COMPILER_GCC - if (__libcpp_is_constant_evaluated()) { - for (; __count; --__count, ++__lhs, ++__rhs) { - if (*__lhs < *__rhs) - return -1; - if (*__rhs < *__lhs) - return 1; - } - return 0; - } -#endif - return __builtin_memcmp(__lhs, __rhs, __count); -} - -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const char* -__constexpr_char_memchr(const char* __str, int __char, size_t __count) { -#if __has_builtin(__builtin_char_memchr) - return __builtin_char_memchr(__str, __char, __count); -#else - if (!__libcpp_is_constant_evaluated()) - return static_cast(std::memchr(__str, __char, __count)); - for (; __count; --__count) { - if (*__str == __char) - return __str; - ++__str; - } - return nullptr; -#endif -} - _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP_CSTRING diff --git a/libcxx/include/fstream b/libcxx/include/fstream --- a/libcxx/include/fstream +++ b/libcxx/include/fstream @@ -189,7 +189,6 @@ #include <__utility/unreachable.h> #include #include -#include #include #include #include diff --git a/libcxx/include/module.modulemap.in b/libcxx/include/module.modulemap.in --- a/libcxx/include/module.modulemap.in +++ b/libcxx/include/module.modulemap.in @@ -1380,6 +1380,7 @@ export string_view module __string { module char_traits { private header "__string/char_traits.h" } + module constexpr_c_functions { private header "__string/constexpr_c_functions.h" } module extern_template_lists { private header "__string/extern_template_lists.h" } module string_fwd { private header "__fwd/string.h" } } diff --git a/libcxx/include/regex b/libcxx/include/regex --- a/libcxx/include/regex +++ b/libcxx/include/regex @@ -773,7 +773,6 @@ #include <__utility/move.h> #include <__utility/pair.h> #include <__utility/swap.h> -#include #include #include #include diff --git a/libcxx/src/include/ryu/common.h b/libcxx/src/include/ryu/common.h --- a/libcxx/src/include/ryu/common.h +++ b/libcxx/src/include/ryu/common.h @@ -43,7 +43,8 @@ // clang-format off #include <__assert> -#include "__config" +#include <__config> +#include _LIBCPP_BEGIN_NAMESPACE_STD diff --git a/libcxx/test/libcxx/private_headers.verify.cpp b/libcxx/test/libcxx/private_headers.verify.cpp --- a/libcxx/test/libcxx/private_headers.verify.cpp +++ b/libcxx/test/libcxx/private_headers.verify.cpp @@ -588,6 +588,7 @@ #include <__split_buffer> // expected-error@*:* {{use of private header from outside its module: '__split_buffer'}} #include <__std_stream> // expected-error@*:* {{use of private header from outside its module: '__std_stream'}} #include <__string/char_traits.h> // expected-error@*:* {{use of private header from outside its module: '__string/char_traits.h'}} +#include <__string/constexpr_c_functions.h> // expected-error@*:* {{use of private header from outside its module: '__string/constexpr_c_functions.h'}} #include <__string/extern_template_lists.h> // expected-error@*:* {{use of private header from outside its module: '__string/extern_template_lists.h'}} #include <__thread/poll_with_backoff.h> // expected-error@*:* {{use of private header from outside its module: '__thread/poll_with_backoff.h'}} #include <__thread/timed_backoff_policy.h> // expected-error@*:* {{use of private header from outside its module: '__thread/timed_backoff_policy.h'}} diff --git a/libcxx/test/libcxx/strings/c.strings/constexpr.cstring.compile.pass.cpp b/libcxx/test/libcxx/strings/c.strings/constexpr.cstring.compile.pass.cpp --- a/libcxx/test/libcxx/strings/c.strings/constexpr.cstring.compile.pass.cpp +++ b/libcxx/test/libcxx/strings/c.strings/constexpr.cstring.compile.pass.cpp @@ -8,9 +8,11 @@ // UNSUPPORTED: c++03, c++11 +// ADDITIONAL_COMPILE_FLAGS: -Wno-private-header + // Check that __constexpr_* cstring functions are actually constexpr -#include +#include <__string/constexpr_c_functions.h> static_assert(std::__constexpr_strlen("Banane") == 6, ""); static_assert(std::__constexpr_memcmp("Banane", "Banand", 6) == 1, ""); diff --git a/libcxx/test/libcxx/transitive_includes/cxx03.csv b/libcxx/test/libcxx/transitive_includes/cxx03.csv --- a/libcxx/test/libcxx/transitive_includes/cxx03.csv +++ b/libcxx/test/libcxx/transitive_includes/cxx03.csv @@ -112,6 +112,7 @@ chrono cstddef chrono cstdint chrono cstdlib +chrono cstring chrono ctime chrono limits chrono ratio @@ -328,7 +329,6 @@ format cstddef format cstdint format cstdlib -format cstring format initializer_list format limits format locale diff --git a/libcxx/test/libcxx/transitive_includes/cxx11.csv b/libcxx/test/libcxx/transitive_includes/cxx11.csv --- a/libcxx/test/libcxx/transitive_includes/cxx11.csv +++ b/libcxx/test/libcxx/transitive_includes/cxx11.csv @@ -112,6 +112,7 @@ chrono cstddef chrono cstdint chrono cstdlib +chrono cstring chrono ctime chrono limits chrono ratio @@ -328,7 +329,6 @@ format cstddef format cstdint format cstdlib -format cstring format initializer_list format limits format locale diff --git a/libcxx/test/libcxx/transitive_includes/cxx14.csv b/libcxx/test/libcxx/transitive_includes/cxx14.csv --- a/libcxx/test/libcxx/transitive_includes/cxx14.csv +++ b/libcxx/test/libcxx/transitive_includes/cxx14.csv @@ -112,6 +112,7 @@ chrono cstddef chrono cstdint chrono cstdlib +chrono cstring chrono ctime chrono limits chrono ratio @@ -330,7 +331,6 @@ format cstddef format cstdint format cstdlib -format cstring format initializer_list format limits format locale diff --git a/libcxx/test/libcxx/transitive_includes/cxx17.csv b/libcxx/test/libcxx/transitive_includes/cxx17.csv --- a/libcxx/test/libcxx/transitive_includes/cxx17.csv +++ b/libcxx/test/libcxx/transitive_includes/cxx17.csv @@ -112,6 +112,7 @@ chrono cstddef chrono cstdint chrono cstdlib +chrono cstring chrono ctime chrono limits chrono ratio @@ -330,7 +331,6 @@ format cstddef format cstdint format cstdlib -format cstring format initializer_list format limits format locale diff --git a/libcxx/test/libcxx/transitive_includes/cxx20.csv b/libcxx/test/libcxx/transitive_includes/cxx20.csv --- a/libcxx/test/libcxx/transitive_includes/cxx20.csv +++ b/libcxx/test/libcxx/transitive_includes/cxx20.csv @@ -338,7 +338,6 @@ format cstddef format cstdint format cstdlib -format cstring format initializer_list format limits format locale diff --git a/libcxx/test/libcxx/transitive_includes/cxx2b.csv b/libcxx/test/libcxx/transitive_includes/cxx2b.csv --- a/libcxx/test/libcxx/transitive_includes/cxx2b.csv +++ b/libcxx/test/libcxx/transitive_includes/cxx2b.csv @@ -68,7 +68,6 @@ charconv cstddef charconv cstdint charconv cstdlib -charconv cstring charconv initializer_list charconv limits charconv type_traits @@ -79,7 +78,6 @@ chrono cstddef chrono cstdint chrono cstdlib -chrono cstring chrono ctime chrono initializer_list chrono limits @@ -258,7 +256,6 @@ format cstddef format cstdint format cstdlib -format cstring format initializer_list format limits format locale diff --git a/libcxxabi/test/test_demangle.pass.cpp b/libcxxabi/test/test_demangle.pass.cpp --- a/libcxxabi/test/test_demangle.pass.cpp +++ b/libcxxabi/test/test_demangle.pass.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -30051,7 +30052,7 @@ {"_Zcv1BIRT_EIS1_E", "operator B<><>"}, {"_ZN2FnIXgs4BaseEX4BaseEEEvv","void Fn<::Base, Base>()"}, - + {"_ZN2FnIXgsnw_iEEXna_ipiLi4EEEEEvv", "void Fn<::new int, new[] int(4)>()"}, {"_ZN2FnIXnwLj4E_iEEXgsnaLj4E_ipiLi4EEEEEvv", "void Fn()"}, {"_ZN2FnIXgsdlLi4EEXdaLi4EEEEvv", "void Fn<::delete 4, delete[] 4>()"},