From: Jason Merrill <jason@redhat.com>
To: Marek Polacek <polacek@redhat.com>,
GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] c++: ICE with deferred noexcept when deducing targs [PR82099]
Date: Tue, 5 Jan 2021 11:02:58 -0500 [thread overview]
Message-ID: <e3b96ea0-709b-1f18-c298-1afb7d6d7c05@redhat.com> (raw)
In-Reply-To: <20210105013118.692897-1-polacek@redhat.com>
On 1/4/21 8:31 PM, Marek Polacek wrote:
> 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<int> 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?
OK.
> 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 <typename T, typename U>
> +void bar (T &x, T &y, U u)
> +{
> + u (x, y);
> +}
> +
> +template <typename T>
> +void baz (T &x, T &y) noexcept (noexcept (x == y));
> +
> +void
> +foo (int x, int y)
> +{
> + bar (x, y, baz<int>);
> +}
> 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<class T>
> void foo() noexcept(T::value);
>
> base-commit: f262a3518877ccce9ed41b2e152c3a3564727bd6
>
prev parent reply other threads:[~2021-01-05 16:03 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-05 1:31 Marek Polacek
2021-01-05 16:02 ` Jason Merrill [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e3b96ea0-709b-1f18-c298-1afb7d6d7c05@redhat.com \
--to=jason@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=polacek@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).