public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jason Merrill <jason@redhat.com>
To: Patrick Palka <ppalka@redhat.com>
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [PATCH 3/1] c++: Fix return type deduction during satisfaction
Date: Mon, 14 Dec 2020 22:20:41 -0500	[thread overview]
Message-ID: <b7d97135-e56c-fcb3-bfc6-75b6c4a7b361@redhat.com> (raw)
In-Reply-To: <1ec04d61-d38c-d6c2-79da-d0aa359920dc@idea>

On 12/14/20 3:47 PM, Patrick Palka wrote:
> On Mon, 14 Dec 2020, Jason Merrill wrote:
> 
>> On 12/14/20 1:07 PM, Patrick Palka wrote:
>>> During satisfaction that's entered through the three-parameter version
>>> of satisfy_declaration_constraints, current_function_decl gets set to
>>> the dependent DECL_TEMPLATE_RESULT for sake of access checking.  This
>>> makes the predicate in_template_function return true during satisfaction
>>> from this entrypoint, which in turn makes calls to mark_used exit early
>>> before it does its full processing.  This leads to us accepting the
>>> invalid testcase below due to mark_used never attempting to deduce the
>>> return type of A::foo() and detecting failure thereof.
>>>
>>> It seems wrong for in_template_function to return true during
>>> instantiation or during satisfaction, so this patch strengthens
>>> in_template_function to additionally check current_instantiation().
>>
>> This seems like it ought to work, but I also wonder about looking at
>> cfun->decl (which is less volatile) instead of current_function_decl for
>> in_template_function.
> 
> That works well, so far it's passed make check-c++.  I'm fully testing
> the following patch:

OK.

> -- >8 --
> 
> Subject: [PATCH] c++: Fix return type deduction during satisfaction
> 
> During satisfaction that's entered through the three-parameter version
> of satisfy_declaration_constraints, current_function_decl gets set to
> the dependent DECL_TEMPLATE_RESULT for sake of access checking.  This
> makes the predicate in_template_function return true during satisfaction
> from this entrypoint, which in turn makes calls to mark_used exit early
> before it does its full processing.  This leads to us accepting the
> invalid testcase below due to mark_used never attempting to deduce the
> return type of A::foo() and detecting failure thereof.
> 
> It seems wrong for in_template_function to be true during instantiation
> or during satisfaction, so this patch makes in_template_function inspect
> the less volatile cfun->decl instead of current_function_decl.
> 
> gcc/cp/ChangeLog:
> 
> 	* pt.c (in_template_function): Inspect cfun->decl instead of
> 	current_function_decl.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* g++.dg/cpp2a/concepts-requires23.C: New test.
> ---
>   gcc/cp/pt.c                                      | 6 ++++--
>   gcc/testsuite/g++.dg/cpp2a/concepts-requires23.C | 9 +++++++++
>   2 files changed, 13 insertions(+), 2 deletions(-)
>   create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-requires23.C
> 
> diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
> index 5b13f125002..ce2e8797aae 100644
> --- a/gcc/cp/pt.c
> +++ b/gcc/cp/pt.c
> @@ -10805,14 +10805,16 @@ uses_template_parms (tree t)
>     return dependent_p;
>   }
>   
> -/* Returns true iff current_function_decl is an incompletely instantiated
> +/* Returns true iff we're processing an incompletely instantiated function
>      template.  Useful instead of processing_template_decl because the latter
>      is set to 0 during instantiate_non_dependent_expr.  */
>   
>   bool
>   in_template_function (void)
>   {
> -  tree fn = current_function_decl;
> +  /* Inspect the less volatile cfun->decl instead of current_function_decl;
> +     the latter might get set for e.g. access checking during satisfaction.  */
> +  tree fn = cfun ? cfun->decl : NULL_TREE;
>     bool ret;
>     ++processing_template_decl;
>     ret = (fn && DECL_LANG_SPECIFIC (fn)
> diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-requires23.C b/gcc/testsuite/g++.dg/cpp2a/concepts-requires23.C
> new file mode 100644
> index 00000000000..e109beaac4f
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-requires23.C
> @@ -0,0 +1,9 @@
> +// { dg-do compile { target c++20 } }
> +
> +// Verify f<A>'s associated constraints evaluate to false due
> +// to return type deduction failure for A::foo().
> +
> +template <class T> concept fooable = requires { T::foo(0); };
> +template <fooable T> int f ();
> +struct A { static auto *foo(auto); };
> +int a = f<A>(); // { dg-error "no match" }
> 


      reply	other threads:[~2020-12-15  3:20 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-14 18:07 Patrick Palka
2020-12-14 18:07 ` [PATCH 4/1] c++: More precise tracking of potentially unstable satisfaction Patrick Palka
2020-12-14 19:18   ` Jason Merrill
2020-12-14 20:29     ` Patrick Palka
2020-12-16 21:55       ` Jason Merrill
2020-12-16 23:24         ` Patrick Palka
2020-12-17 13:53           ` Jason Merrill
2020-12-14 18:58 ` [PATCH 3/1] c++: Fix return type deduction during satisfaction Jason Merrill
2020-12-14 20:47   ` Patrick Palka
2020-12-15  3:20     ` 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=b7d97135-e56c-fcb3-bfc6-75b6c4a7b361@redhat.com \
    --to=jason@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=ppalka@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).