diff --git a/libcxx/docs/ReleaseNotes.rst b/libcxx/docs/ReleaseNotes.rst --- a/libcxx/docs/ReleaseNotes.rst +++ b/libcxx/docs/ReleaseNotes.rst @@ -51,6 +51,12 @@ has been shipping since LLVM 14, so the Coroutines TS implementation is being removed per our policy for removing TSes. +- Several incidental transitive includes have been removed from libc++. Those + includes are removed based on the language version used. Incidental transitive + inclusions of the following headers have been removed: + + - C++2b: ``cstring`` + 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 @@ -540,6 +540,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/__hash_table b/libcxx/include/__hash_table --- a/libcxx/include/__hash_table +++ b/libcxx/include/__hash_table @@ -30,7 +30,6 @@ #include <__utility/pair.h> #include <__utility/swap.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(std::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 @@ -95,7 +95,6 @@ #include // for log2f #include #include -#include #include #include @@ -841,6 +840,7 @@ #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 # include +# include # include #endif 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/list b/libcxx/include/list --- a/libcxx/include/list +++ b/libcxx/include/list @@ -207,7 +207,6 @@ #include <__utility/forward.h> #include <__utility/move.h> #include <__utility/swap.h> -#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 @@ -1356,6 +1356,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/include/string b/libcxx/include/string --- a/libcxx/include/string +++ b/libcxx/include/string @@ -570,7 +570,6 @@ #include #include // EOF #include -#include #include #include #include diff --git a/libcxx/include/vector b/libcxx/include/vector --- a/libcxx/include/vector +++ b/libcxx/include/vector @@ -314,7 +314,6 @@ #include <__utility/swap.h> #include #include -#include #include // for forward declaration of vector #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 @@ -571,6 +571,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 @@ -327,7 +327,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 @@ -327,7 +327,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 @@ -329,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/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 @@ -329,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/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 @@ -69,7 +69,6 @@ charconv cstddef charconv cstdint charconv cstdlib -charconv cstring charconv initializer_list charconv limits charconv type_traits @@ -81,7 +80,6 @@ chrono cstddef chrono cstdint chrono cstdlib -chrono cstring chrono ctime chrono initializer_list chrono limits @@ -261,7 +259,6 @@ format cstddef format cstdint format cstdlib -format cstring format initializer_list format limits format locale