From patchwork Mon Mar 6 23:59:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 1752838 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=qIrfd48f; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.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 (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PVwZS60DFz1yWx for ; Tue, 7 Mar 2023 11:00:47 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C6C6738515F4 for ; Tue, 7 Mar 2023 00:00:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C6C6738515F4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678147242; bh=TKSPXdxgJWIdZy/HKe9mYnIFrJBe+qhVDbb1lgXITio=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=qIrfd48fCZx9fKXbMafUzhLBtvKsGhKylJJYIphNZT60rHhQmFqW8zIj46N8S4pfA Ec1e6oH4F8ZxeI3kx+YjH6bwUtmoiDqbDLzsCWvTCIn7d30eRl0QkhbD25K1EZjznC JFXyaqugfOE7Ra8WfWHpV1sBKKCXgzDJ6msK3Evg= 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 ESMTPS id 5FD623858C66 for ; Tue, 7 Mar 2023 00:00:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5FD623858C66 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-462-lI8DGsDmMYu-ZSNklTOr4g-1; Mon, 06 Mar 2023 19:00:02 -0500 X-MC-Unique: lI8DGsDmMYu-ZSNklTOr4g-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 56DE31C05ECB for ; Tue, 7 Mar 2023 00:00:02 +0000 (UTC) Received: from pdp-11.lan (unknown [10.22.35.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 259E514171C4; Tue, 7 Mar 2023 00:00:02 +0000 (UTC) To: GCC Patches , Jason Merrill Subject: [PATCH] c++: noexcept and copy elision [PR109030] Date: Mon, 6 Mar 2023 18:59:57 -0500 Message-Id: <20230306235957.390533-1-polacek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.3 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_H2, 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Marek Polacek via Gcc-patches From: Marek Polacek Reply-To: Marek Polacek Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" When processing a noexcept, constructors aren't elided: build_over_call has /* It's unsafe to elide the constructor when handling a noexcept-expression, it may evaluate to the wrong value (c++/53025). */ && (force_elide || cp_noexcept_operand == 0)) so the assert I added recently needs to be relaxed a little bit. Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? PR c++/109030 gcc/cp/ChangeLog: * constexpr.cc (cxx_eval_call_expression): Relax assert. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/noexcept77.C: New test. --- gcc/cp/constexpr.cc | 6 +++++- gcc/testsuite/g++.dg/cpp0x/noexcept77.C | 9 +++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/noexcept77.C base-commit: dfb14cdd796ad9df6b5f2def047ef36b29385902 diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc index 364695b762c..5384d0e8e46 100644 --- a/gcc/cp/constexpr.cc +++ b/gcc/cp/constexpr.cc @@ -2869,7 +2869,11 @@ cxx_eval_call_expression (const constexpr_ctx *ctx, tree t, /* We used to shortcut trivial constructor/op= here, but nowadays we can only get a trivial function here with -fno-elide-constructors. */ - gcc_checking_assert (!trivial_fn_p (fun) || !flag_elide_constructors); + gcc_checking_assert (!trivial_fn_p (fun) + || !flag_elide_constructors + /* We don't elide constructors when processing + a noexcept-expression. */ + || cp_noexcept_operand); bool non_constant_args = false; new_call.bindings diff --git a/gcc/testsuite/g++.dg/cpp0x/noexcept77.C b/gcc/testsuite/g++.dg/cpp0x/noexcept77.C new file mode 100644 index 00000000000..16db8eb79ee --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/noexcept77.C @@ -0,0 +1,9 @@ +// PR c++/109030 +// { dg-do compile { target c++11 } } + +struct foo { }; + +struct __as_receiver { + foo empty_env; +}; +void sched(foo __fun) noexcept(noexcept(__as_receiver{__fun})) { }