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>, gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] c++: implicit dummy object in requires clause [PR103198]
Date: Wed, 17 Nov 2021 13:36:30 -0500	[thread overview]
Message-ID: <f5b7a87d-1bbe-3ffd-5a93-ce5d733d663c@redhat.com> (raw)
In-Reply-To: <20211112012529.1829478-1-ppalka@redhat.com>

On 11/11/21 20:25, Patrick Palka wrote:
> In the testcase below satisfaction misbehaves for f and g ultimately
> because find_template_parameters fails to notice that the constraint
> 'val.x' depends on the template parameters of the class template.
> In contrast, satisfaction works just fine for h.
> 
> The problem seems to come down to a difference in how any_template_parm_r
> handles 'this' vs a dummy object: we walk TREE_TYPE of the former but
> not the latter, and this causes us to miss the tparm dependencies in
> f/g's constraints since in their case the implicit object parameter
> through which we access 'val' is a dummy object.  (For h, since we know
> it's a non-static member function when parsing its trailing constraints,
> the implicit object parameter is 'this' instead of a dummy object.)
> 
> This patch fixes this inconsistency by making any_template_parm_r also
> walk into the TREE_TYPE of a dummy object, as is already done for
> 'this'.
> 
> Bootstrapped and regtested on x86_64-pc-linux-gnu, also tested on
> cmcstl2 and range-v3, does this look OK for trunk and 11?
> 
> 	PR c++/103198
> 
> gcc/cp/ChangeLog:
> 
> 	* pt.c (any_template_parm_r): Walk the TREE_TYPE of a dummy
> 	object.

Should we handle CONVERT_EXPR with the various casts in cp_walk_subtrees?

> gcc/testsuite/ChangeLog:
> 
> 	* g++.dg/cpp2a/concepts-this1.C: New test.
> ---
>   gcc/cp/pt.c                                 |  5 ++++
>   gcc/testsuite/g++.dg/cpp2a/concepts-this1.C | 30 +++++++++++++++++++++
>   2 files changed, 35 insertions(+)
>   create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-this1.C
> 
> diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
> index 82bf7dc26f6..fa55857d783 100644
> --- a/gcc/cp/pt.c
> +++ b/gcc/cp/pt.c
> @@ -10766,6 +10766,11 @@ any_template_parm_r (tree t, void *data)
>   	WALK_SUBTREE (TREE_TYPE (t));
>         break;
>   
> +    case CONVERT_EXPR:
> +      if (is_dummy_object (t))
> +	WALK_SUBTREE (TREE_TYPE (t));
> +      break;
> +
>       default:
>         break;
>       }
> diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-this1.C b/gcc/testsuite/g++.dg/cpp2a/concepts-this1.C
> new file mode 100644
> index 00000000000..d717028201a
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-this1.C
> @@ -0,0 +1,30 @@
> +// PR c++/103198
> +// { dg-do compile { target c++20 } }
> +
> +template<class T, class = void>
> +struct A {
> +  T val;
> +
> +  template<class U>
> +    requires requires { val.x; }
> +  void f(U);
> +
> +  static void g(int)
> +    requires requires { val.x; };
> +
> +  void h(int)
> +    requires requires { val.x; };
> +};
> +
> +struct B { int x; };
> +struct C { };
> +
> +int main() {
> +  A<B>().f(0);
> +  A<B>().g(0);
> +  A<B>().h(0);
> +
> +  A<C>().f(0); // { dg-error "no match" }
> +  A<C>().g(0); // { dg-error "no match" }
> +  A<C>().h(0); // { dg-error "no match" }
> +}
> 


  reply	other threads:[~2021-11-17 18:36 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-12  1:25 Patrick Palka
2021-11-17 18:36 ` Jason Merrill [this message]
2021-11-17 19:52   ` Patrick Palka
2021-11-18 19:25     ` Jason Merrill
2021-11-18 19:49       ` Patrick Palka
2021-11-18 22:15         ` Jason Merrill

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=f5b7a87d-1bbe-3ffd-5a93-ce5d733d663c@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).