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 [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 773A73857C7D for ; Tue, 5 Jan 2021 01:31:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 773A73857C7D Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-503-qVVDQftFNb2xxiVAv-jxZg-1; Mon, 04 Jan 2021 20:31:26 -0500 X-MC-Unique: qVVDQftFNb2xxiVAv-jxZg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 62AB8800D53 for ; Tue, 5 Jan 2021 01:31:25 +0000 (UTC) Received: from pdp-11.redhat.com (ovpn-117-180.rdu2.redhat.com [10.10.117.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id E34FB60BE5; Tue, 5 Jan 2021 01:31:24 +0000 (UTC) From: Marek Polacek To: Jason Merrill , GCC Patches Subject: [PATCH] c++: ICE with deferred noexcept when deducing targs [PR82099] Date: Mon, 4 Jan 2021 20:31:18 -0500 Message-Id: <20210105013118.692897-1-polacek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" X-Spam-Status: No, score=-14.6 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_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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-List-Received-Date: Tue, 05 Jan 2021 01:31:29 -0000 In this test we ICE in type_throw_all_p because it got a deferred noexcept which it shouldn't. Here's the story: In noexcept61.C, we call bar, so we perform overload resolution. When adding the (only) candidate, we need to deduce template arguments, so call fn_type_unification as usually. That deduces U to void (*) (int &, int &) which is correct, but its noexcept-spec is deferred_noexcept. Then we call add_function_candidate (bar), wherein we try to create an implicit conversion sequence for every argument. Since baz is of unknown type, we instantiate_type it; it is a TEMPLATE_ID_EXPR so that calls resolve_address_of_overloaded_function. But we crash there, because target_type contains the deferred_noexcept. So we need to maybe_instantiate_noexcept before we can compare types. resolve_overloaded_unification seemed like the appropriate spot, now fn_type_unification produces the function type with its noexcept-spec instantiated. This shouldn't go against CWG 1330 because here we really need to instantiate the noexcept-spec. This also fixes class-deduction76.C, a dg-ice test I recently added, therefore this fix also fixes c++/90799, yay. Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? gcc/cp/ChangeLog: PR c++/82099 * pt.c (resolve_overloaded_unification): Call maybe_instantiate_noexcept after instantiating the function decl. gcc/testsuite/ChangeLog: PR c++/82099 * g++.dg/cpp1z/class-deduction76.C: Remove dg-ice. * g++.dg/cpp0x/noexcept61.C: New test. --- gcc/cp/pt.c | 3 +++ gcc/testsuite/g++.dg/cpp0x/noexcept61.C | 17 +++++++++++++++++ gcc/testsuite/g++.dg/cpp1z/class-deduction76.C | 1 - 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/noexcept61.C diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 062ef858501..0d061adc2ed 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -22373,6 +22373,9 @@ resolve_overloaded_unification (tree tparms, --function_depth; } + if (flag_noexcept_type) + maybe_instantiate_noexcept (fn, tf_none); + elem = TREE_TYPE (fn); if (try_one_overload (tparms, targs, tempargs, parm, elem, strict, sub_strict, addr_p, explain_p) diff --git a/gcc/testsuite/g++.dg/cpp0x/noexcept61.C b/gcc/testsuite/g++.dg/cpp0x/noexcept61.C new file mode 100644 index 00000000000..653cd7e6680 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/noexcept61.C @@ -0,0 +1,17 @@ +// PR c++/82099 +// { dg-do compile { target c++11 } } + +template +void bar (T &x, T &y, U u) +{ + u (x, y); +} + +template +void baz (T &x, T &y) noexcept (noexcept (x == y)); + +void +foo (int x, int y) +{ + bar (x, y, baz); +} diff --git a/gcc/testsuite/g++.dg/cpp1z/class-deduction76.C b/gcc/testsuite/g++.dg/cpp1z/class-deduction76.C index 23bb6e8fa9a..a131a386baa 100644 --- a/gcc/testsuite/g++.dg/cpp1z/class-deduction76.C +++ b/gcc/testsuite/g++.dg/cpp1z/class-deduction76.C @@ -1,6 +1,5 @@ // PR c++/90799 // { dg-do compile { target c++17 } } -// { dg-ice "unify" } template void foo() noexcept(T::value); base-commit: f262a3518877ccce9ed41b2e152c3a3564727bd6 -- 2.29.2