From patchwork Thu Aug 1 21:07:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1968040 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=XxwTdrH4; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WZhSH4mvzz1ydv for ; Fri, 2 Aug 2024 07:10:07 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 48D16385DDF9 for ; Thu, 1 Aug 2024 21:10:05 +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.133.124]) by sourceware.org (Postfix) with ESMTP id E27233858CD9 for ; Thu, 1 Aug 2024 21:09:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E27233858CD9 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 E27233858CD9 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722546541; cv=none; b=dBuBkBfl50h8vDwI1UVtmf/fByG6HHS545ZzA8bjw3URNBsq1TqbXeEZUUZPAqIeFPwdEY/O9m4j2jlkelDKVLMZFV1enQmSMoJ7sCZuTB5/iELWQaHeVVqI7qYL9+SrVJUgSwxRSSgz/5vFMfy2PpgzMabLtnQh1XII/B2esGk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722546541; c=relaxed/simple; bh=pZYRs9VM5csrMLoI32Fh7TdrQfFD+2xkyNdkuEnv6Qc=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=TN2pQg2vxUdA0TkJMW7a3aBzdzZn2plv/QlDZx75+RaxHVYRqk1jbZ5dk7L4QsHIUKchukw1nNOPB4sNozxMug0QQeAMIIF6tre1OPpVpuhy8QkUqomwYjrr1NuNedHlfO2iZb/bxCPOIv7botgrwflAMcZOlmIDKKttqUEstBw= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1722546540; 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=fpmHC14ibr2KUcjC8A3aF1W3l5m6gNn87UKbn3HzG0g=; b=XxwTdrH4YOoUxrj2QsrsZQVUhmWGtAGYZmbZ8KcQQRwBg+mvIpy/+HC2GOwk2qBQQHI7/l UJlJIhCynMwbwLLvOLh0L9I+L2lTYK1AXMfgkMyXvkSvGTVPYsMDIsasdrsRpv689A8Tle 92cqMUI6BOKu6TTsOadVvtSxQkdL58s= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-468-sx8u_ZkdMNWyHF6XWxqWzA-1; Thu, 01 Aug 2024 17:08:58 -0400 X-MC-Unique: sx8u_ZkdMNWyHF6XWxqWzA-1 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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 mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 07E5D19560A1; Thu, 1 Aug 2024 21:08:57 +0000 (UTC) Received: from localhost (unknown [10.42.28.21]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0495719560AE; Thu, 1 Aug 2024 21:08:54 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Remove noexcept from non-const std::basic_string::data() [PR99942] Date: Thu, 1 Aug 2024 22:07:23 +0100 Message-ID: <20240801210853.385911-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.5 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 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~incoming=patchwork.ozlabs.org@gcc.gnu.org I've had this in my local tree for ages, time to push it I think. It's better to be non-conforming than to lie and posibly terminate the whole process (the COW std::string is already non-conforming in C++11 and later anyway). Tested x86_64-linux. Pushed to trunk. -- >8 -- The C++17 non-const overload of data() allows modifying the string contents directly, so for the COW string we must do a copy-on-write to unshare it. That means allocating, which can throw, so it shouldn't be noexcept. libstdc++-v3/ChangeLog: PR libstdc++/99942 * include/bits/cow_string.h (data()): Change to noexcept(false). --- libstdc++-v3/include/bits/cow_string.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libstdc++-v3/include/bits/cow_string.h b/libstdc++-v3/include/bits/cow_string.h index 5d81bfc1230..75a2d887ad6 100644 --- a/libstdc++-v3/include/bits/cow_string.h +++ b/libstdc++-v3/include/bits/cow_string.h @@ -2267,9 +2267,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * * This is a pointer to the character sequence held by the string. * Modifying the characters in the sequence is allowed. + * + * The standard requires this function to be `noexcept` but for the + * Copy-On-Write string implementation it can throw. This function + * allows modifying the string contents directly, which means we + * must copy-on-write to unshare it, which requires allocating memory. */ _CharT* - data() noexcept + data() noexcept(false) { _M_leak(); return _M_data();