From patchwork Wed Jul 10 21:11:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1959022 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=hrXBU7rz; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; 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 [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4WK9cB4LVhz1xqr for ; Thu, 11 Jul 2024 07:15:06 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D74183870896 for ; Wed, 10 Jul 2024 21:15:04 +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 A45B0386103F for ; Wed, 10 Jul 2024 21:14:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A45B0386103F 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 A45B0386103F 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=1720646085; cv=none; b=ZHw3zvplwY3MhFz5P5UTqUQ/kK6NAc8KlweZNcYlfg3CR+fMRgvIUaIfIf1UO3IbtnsMaIoS00IDUqlG0hMgRh6eAB4+C6mbJJH60yoRxl+P72JKvMOPRrom3Csrr4tNIqZsC7GVQiddnRm48svaV+XavuZFvn4BlMF4NG26rMI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1720646085; c=relaxed/simple; bh=QBjJoEXodPr+jqszzikDf+TXB8zWGL1S+Cj4XICK7WQ=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=xnSXmM0aZTcFS8WoUfirCNEvsipV8k51bKHl3VjxYtRho68NS0s9RVw3RKuDohfHSYirdd6/K++o160q2rQ9FWCxpUoPcDkB+F2vTNwdsAvjyZYp5qWBeE5+z1BMuHB1g+SY2NPfmGBNoAs4SMwaD3fhffYAbEtGilIV4krZF8s= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720646083; 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=QPOOH8rvFgx8fzv8rt1d3Vr5nywjdeCfBki3ZnkfmE0=; b=hrXBU7rzlWDvFSBE7UmUlsb1J+O/pIMIrEJDW7tOYD0pk8EtURm88w7CVJJYph4U4G+EUe s0CZsIkTOHiliqz6Yff9ghaovp0OdlVYlqSdS3ewCJQFuRs9ZjWf4B2S4P73XahyAktp2q 2ot7xs+XZ+Xql7wI/sqITJUZRr86q+8= Received: from mx-prod-mc-01.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-635-RrNwiGjdP_iia4pYpAk-Jw-1; Wed, 10 Jul 2024 17:14:41 -0400 X-MC-Unique: RrNwiGjdP_iia4pYpAk-Jw-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C07FD1955F44; Wed, 10 Jul 2024 21:14:40 +0000 (UTC) Received: from localhost (unknown [10.42.28.19]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 41C1D19560AA; Wed, 10 Jul 2024 21:14:38 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Make std::basic_format_context non-copyable [PR114387] Date: Wed, 10 Jul 2024 22:11:57 +0100 Message-ID: <20240710211437.918580-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.1 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=ham 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 Tested x86_64-linux. Pushed to trunk. Probably a good idea to backport it to 13 and 14, for consistency. -- >8 -- Users are not supposed to create objects of this type, and there's no reason it needs to be copyable. LWG 4061 makes it non-copyable and non-default constructible. libstdc++-v3/ChangeLog: PR libstdc++/114387 * include/std/format (basic_format_context): Define copy operations as deleted, as per LWG 4061. * testsuite/std/format/context.cc: New test. --- libstdc++-v3/include/std/format | 7 +++- libstdc++-v3/testsuite/std/format/context.cc | 36 ++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 libstdc++-v3/testsuite/std/format/context.cc diff --git a/libstdc++-v3/include/std/format b/libstdc++-v3/include/std/format index 48deba2bcb2..16cee0d3c74 100644 --- a/libstdc++-v3/include/std/format +++ b/libstdc++-v3/include/std/format @@ -3851,6 +3851,12 @@ namespace __format : _M_args(__args), _M_out(std::move(__out)), _M_loc(__loc) { } + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 4061. Should std::basic_format_context be + // default-constructible/copyable/movable? + basic_format_context(const basic_format_context&) = delete; + basic_format_context& operator=(const basic_format_context&) = delete; + template friend _Out2 __format::__do_vformat_to(_Out2, basic_string_view<_CharT2>, @@ -3858,7 +3864,6 @@ namespace __format const locale*); public: - basic_format_context() = default; ~basic_format_context() = default; using iterator = _Out; diff --git a/libstdc++-v3/testsuite/std/format/context.cc b/libstdc++-v3/testsuite/std/format/context.cc new file mode 100644 index 00000000000..5cc5e9c9ba2 --- /dev/null +++ b/libstdc++-v3/testsuite/std/format/context.cc @@ -0,0 +1,36 @@ +// { dg-do compile { target c++20 } } + +#include + +template +concept format_context_reqs = std::is_destructible_v + && (!std::is_default_constructible_v) + && (!std::is_copy_constructible_v) + && (!std::is_move_constructible_v) + && (!std::is_copy_assignable_v) + && (!std::is_move_assignable_v) + && requires (Context& ctx, const Context& cctx) { + typename Context::iterator; + typename Context::char_type; + requires std::same_as, + std::formatter>; + { ctx.locale() } -> std::same_as; + { ctx.out() } -> std::same_as; + { ctx.advance_to(ctx.out()) } -> std::same_as; + { cctx.arg(1) } -> std::same_as>; + }; + +template +constexpr bool +check(std::basic_format_context*) +{ + using context = std::basic_format_context; + static_assert( format_context_reqs ); + static_assert( std::is_same_v ); + static_assert( std::is_same_v ); + return true; +} + +static_assert( check( (std::format_context*)nullptr) ); +static_assert( check( (std::wformat_context*)nullptr) ); +static_assert( check( (std::basic_format_context*)nullptr) );