From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678147213; 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=TKSPXdxgJWIdZy/HKe9mYnIFrJBe+qhVDbb1lgXITio=; b=NmHqczZn3Cw6lx0cCEbiAgkrlMcEi416o/dv1i43W+yySmdINQgEpfmZHbg2qxBJPL+/kj d88Qkykt0F0KhMAAsG6EubHTwBYMmM1tpIaZK0TEuJYMuKXB373SUGhorUiqHUAQ1Jts2n nDYLyFJa/xuNk4BTNWUzHZBXqH8EdA8= 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) From: Marek Polacek 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true 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 List-Id: 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 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})) { } base-commit: dfb14cdd796ad9df6b5f2def047ef36b29385902 -- 2.39.2