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: 167856 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2b07:b0:403:3b70:6f57 with SMTP id io7csp792355vqb; Tue, 21 Nov 2023 09:31:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IF0TBfezhy+UCe1PiF+BYlZjYYbourgftZWCXt+B/D92B+7mYaZU7PhDvGBoscMQ2tLhe8V X-Received: by 2002:a05:620a:6604:b0:773:dce0:b2b8 with SMTP id qf4-20020a05620a660400b00773dce0b2b8mr13061668qkn.17.1700587915841; Tue, 21 Nov 2023 09:31:55 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1700587915; cv=pass; d=google.com; s=arc-20160816; b=iGJ8MljdMa1pgizTlvR08Imiu2zU7Eiiee3thTRjOJ+5fpArGYpWYHdCyl5r5f2KoP dNDU7elJrSZKKw/cFKVpmJ7hwsLYi7dpnOIt5/24OKbNhsffMGC/woPgfkPetcqztX43 O3cL2VPLXHGEthFYSHOWl0jLfUOdSbWHN/HO9pPG4FvCcdd5MqDun+kTA2lCUIcHw7Db bkxQDVeSg1FLci/i2WpPCAV3p4OQZA1z6n+Ggg4XM2/+Qs88aP6B0OUVc/dqOwG7jOIW 020e8qKi4tmJoBefgR5/ng9g25nYUD849gEuOjEiWLAa+S9L9m+YBsOaZ1nstDSI/zyW KKww== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=4wewL4LA5/eqeRoMVG9LhTuC8YIO32x2Qnv779YZhMg=; fh=sJ+2/4g29YdyXkoRrFZSpsL2zxijepB7X/1rB0LDDh8=; b=BjNZgOYCwaWGrHh1A81A//sWsYl7utMiSv1fzQ4rRExSE6E+ogIL6QqCczOK/f0Zsr QxM8ZVIP7iqFaDeMKczVHPWdkUGRLbBWX1K6LCfd2Q+4KU5FJFwrXxZshHPSmo7mLtIU AVLVSF7eQSsSPtXK5udziu/GWr+flxz4qOjTW0gJIgLd/lXgJpRp0LWNrOMXPhkiwj1S nIn9jzjWZQ66v8FkU3LuBNKDcWIpcNMWc10SRmPFBqhI38ikhypREEFvecLLfVhJqC42 qXmxjXisZVvoAYEm1uuPr5/VGGjnmtUNplccaUeO4VEmawYKOJ4jYxYxIkvEiTPiAjp9 /xbA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=CryQNk0C; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id qj12-20020a05620a880c00b007788d758a18si9581367qkn.511.2023.11.21.09.31.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 09:31:55 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=CryQNk0C; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DB3B1384646C for ; Tue, 21 Nov 2023 16:12:07 +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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783195674892725635 X-GMAIL-MSGID: 1783195674892725635 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