From patchwork Tue Nov 21 16:11:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 80496 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2DD043861826 for ; Tue, 21 Nov 2023 16:12:00 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id C0F4E385B83E for ; Tue, 21 Nov 2023 16:11:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C0F4E385B83E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C0F4E385B83E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700583103; cv=none; b=XQ+8cKYPy2b+0T3zdsigWvESOnEJPPkh9XZ5CICjpr02I9wZhl4FFEQzvYCxXFFvqx1WEHOuWBrGmaKXbQVdcwEC6wNWEfuYBsqP86peX1jUN+aOgvU24/6FzfhsbHiAWbNoMfAZMZSBC+HDVlq00nl4x5Mwe7UaipRuJpMzH5k= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700583103; c=relaxed/simple; bh=NlxJKQUYLILt1riZMwNn5+cNTCq4WA2Hwnhp1PmlrvE=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=TJIhnidXtB5PJHNquB3x1aJYT9sqn0G5+FPNcj9hFeJJlsT7W6VVuIpLxkfDW4OKOPPO/p0zK0/PbRtvYCDQ7gZ71GBjaFc2vYq0c9yZG9MK6Ai/ujYfr66wXw/VN0wb5JHTkKBHzeDJHYwDjP/0SPveV77bAD23panQqzDnTM8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700583101; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=4wewL4LA5/eqeRoMVG9LhTuC8YIO32x2Qnv779YZhMg=; b=CryQNk0CWFAVti/XOKn2OLH1emXmD3h8f0PEuVvCeF06T6FLFWOaSEXhALKPWxZlEm55Ap Bvvvbyc9fwKw/2GbW9TjBOiMbzoepGUOj0zjfXm8VnINGn0nf8AWOSt5uWDyJXi7IuNghC vw4WMVod8mTsKm5W+GNFvVz11YxJmdQ= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-489-4Ww8moEuMUC9eva0f3SdyQ-1; Tue, 21 Nov 2023 11:11:38 -0500 X-MC-Unique: 4Ww8moEuMUC9eva0f3SdyQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C83FC85A58C; Tue, 21 Nov 2023 16:11:37 +0000 (UTC) Received: from localhost (unknown [10.42.28.240]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8C2492026D4C; Tue, 21 Nov 2023 16:11:37 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Do not declare strtok for C++26 freestanding (P2937R0) Date: Tue, 21 Nov 2023 16:11:07 +0000 Message-ID: <20231121161136.2031190-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org 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 as well as , but we do not currently install our own 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 +#define __glibcxx_want_freestanding_cstring +#include #include #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 + +#ifndef __cpp_lib_freestanding_cstring +# error "Feature test macro for freestanding is missing in " +#elif __cpp_lib_freestanding_cstring < 202311L +# error "Feature test macro for freestanding has wrong value in " +#endif + +#undef __cpp_lib_freestanding_cstring +#include + +#ifndef __cpp_lib_freestanding_cstring +# error "Feature test macro for freestanding is missing in " +#elif __cpp_lib_freestanding_cstring < 202311L +# error "Feature test macro for freestanding has wrong value in " +#endif