Tested x86_64-linux. Pushed to trunk. -- >8 --
This was recently approved for C++26. We should define the __cpp_lib_freestanding_cstring macro in <string.h> as well as <cstring>, but we do not currently install our own <string.h> for most targets. libstdc++-v3/ChangeLog: * include/bits/version.def (freestanding_cstring): Add. * include/bits/version.h: Regenerate. * include/c_compatibility/string.h (strtok): Do not declare for C++26 freestanding. * include/c_global/cstring (strtok): Likewise. * testsuite/21_strings/headers/cstring/version.cc: New test. --- libstdc++-v3/include/bits/version.def | 9 ++ libstdc++-v3/include/bits/version.h | 89 +++++++++++-------- libstdc++-v3/include/c_compatibility/string.h | 2 + libstdc++-v3/include/c_global/cstring | 5 +- .../21_strings/headers/cstring/version.cc | 19 ++++ 5 files changed, 84 insertions(+), 40 deletions(-) create mode 100644 libstdc++-v3/testsuite/21_strings/headers/cstring/version.cc diff --git a/libstdc++-v3/include/bits/version.def b/libstdc++-v3/include/bits/version.def index 1c49ecea25e..605708dfee7 100644 --- a/libstdc++-v3/include/bits/version.def +++ b/libstdc++-v3/include/bits/version.def @@ -1366,6 +1366,15 @@ ftms = { }; }; +ftms = { + name = freestanding_cstring; + values = { + v = 202311; + // This is a C++26 feature, but we support it in C++23. + cxxmin = 23; + }; +}; + ftms = { name = freestanding_expected; values = { diff --git a/libstdc++-v3/include/bits/version.h b/libstdc++-v3/include/bits/version.h index a61d482c662..cacd9375cab 100644 --- a/libstdc++-v3/include/bits/version.h +++ b/libstdc++-v3/include/bits/version.h @@ -1653,6 +1653,17 @@ #undef __glibcxx_want_freestanding_array // from version.def line 1370 +#if !defined(__cpp_lib_freestanding_cstring) +# if (__cplusplus >= 202100L) +# define __glibcxx_freestanding_cstring 202311L +# if defined(__glibcxx_want_all) || defined(__glibcxx_want_freestanding_cstring) +# define __cpp_lib_freestanding_cstring 202311L +# endif +# endif +#endif /* !defined(__cpp_lib_freestanding_cstring) && defined(__glibcxx_want_freestanding_cstring) */ +#undef __glibcxx_want_freestanding_cstring + +// from version.def line 1379 #if !defined(__cpp_lib_freestanding_expected) # if (__cplusplus >= 202100L) && (__cpp_lib_expected) # define __glibcxx_freestanding_expected 202311L diff --git a/libstdc++-v3/include/c_compatibility/string.h b/libstdc++-v3/include/c_compatibility/string.h index 1d9e0d2a9bd..06529af057c 100644 --- a/libstdc++-v3/include/c_compatibility/string.h +++ b/libstdc++-v3/include/c_compatibility/string.h @@ -50,7 +50,9 @@ using std::strpbrk; using std::strrchr; using std::strspn; using std::strstr; +#if _GLIBCXX_HOSTED || __cplusplus <= 202302L using std::strtok; +#endif using std::memset; using std::strerror; using std::strlen; diff --git a/libstdc++-v3/include/c_global/cstring b/libstdc++-v3/include/c_global/cstring index d0a129ac802..f39aae1c82e 100644 --- a/libstdc++-v3/include/c_global/cstring +++ b/libstdc++-v3/include/c_global/cstring @@ -38,7 +38,8 @@ #pragma GCC system_header -#include <bits/c++config.h> +#define __glibcxx_want_freestanding_cstring +#include <bits/version.h> #include <string.h> #ifndef _GLIBCXX_CSTRING @@ -90,7 +91,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION using ::strncmp; using ::strncpy; using ::strspn; +#if _GLIBCXX_HOSTED || __cplusplus <= 202302L using ::strtok; +#endif using ::strxfrm; using ::strchr; using ::strpbrk; diff --git a/libstdc++-v3/testsuite/21_strings/headers/cstring/version.cc b/libstdc++-v3/testsuite/21_strings/headers/cstring/version.cc new file mode 100644 index 00000000000..06735e86a76 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/headers/cstring/version.cc @@ -0,0 +1,19 @@ +// { dg-do compile { target c++26 } } +// { dg-add-options no_pch } + +#include <cstring> + +#ifndef __cpp_lib_freestanding_cstring +# error "Feature test macro for freestanding <cstring> is missing in <cstring>" +#elif __cpp_lib_freestanding_cstring < 202311L +# error "Feature test macro for freestanding <cstring> has wrong value in <cstring>" +#endif + +#undef __cpp_lib_freestanding_cstring +#include <version> + +#ifndef __cpp_lib_freestanding_cstring +# error "Feature test macro for freestanding <cstring> is missing in <version>" +#elif __cpp_lib_freestanding_cstring < 202311L +# error "Feature test macro for freestanding <cstring> has wrong value in <version>" +#endif -- 2.42.0