public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Patrick Palka <ppalka@redhat.com>
To: Jason Merrill <jason@redhat.com>
Cc: Patrick Palka <ppalka@redhat.com>, gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] c++: implicit dummy object in requires clause [PR103198]
Date: Thu, 18 Nov 2021 14:49:51 -0500 (EST)	[thread overview]
Message-ID: <b060bbe-1134-c68d-1b8d-55c4b8d2b7f8@idea> (raw)
In-Reply-To: <e924a895-1b15-4c91-d0de-30147efdc0fc@redhat.com>

On Thu, 18 Nov 2021, Jason Merrill wrote:

> On 11/17/21 14:52, Patrick Palka wrote:
> > On Wed, 17 Nov 2021, Jason Merrill wrote:
> > 
> > > 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?
> > 
> > This seems to work well too.  But I'm not sure about doing this since
> > IIUC cp_walk_subtrees is generally supposed to walk subtrees that are
> > explicitly written in the source code, but when a CONVERT_EXPR
> > corresponds to an implicit conversion then the target type doesn't
> > explicitly appear anywhere.
> 
> We could check is_dummy_object there as well?

Ah I see, sorry for the misunderstanding.  So wouldn't that mean
cp_walk_subtrees will wal the TREE_TYPE of a dummy object but not the
TREE_TYPE of 'this'?  That seems like a weird inconsistency at first
glance.

> 
> > > 
> > > > 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-18 19:49 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
2021-11-17 19:52   ` Patrick Palka
2021-11-18 19:25     ` Jason Merrill
2021-11-18 19:49       ` Patrick Palka [this message]
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=b060bbe-1134-c68d-1b8d-55c4b8d2b7f8@idea \
    --to=ppalka@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jason@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).