public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Patrick Palka <ppalka@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r11-9390] c++: implicit dummy object in requires clause [PR103198]
Date: Wed, 15 Dec 2021 19:55:31 +0000 (GMT)	[thread overview]
Message-ID: <20211215195531.13D3D385842C@sourceware.org> (raw)

https://gcc.gnu.org/g:648d5aa56abd2a0ab36403dd1e14dd225402301a

commit r11-9390-g648d5aa56abd2a0ab36403dd1e14dd225402301a
Author: Patrick Palka <ppalka@redhat.com>
Date:   Thu Nov 18 19:32:22 2021 -0500

    c++: implicit dummy object in requires clause [PR103198]
    
    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 parms 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: it walks the 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 parm 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 parm is 'this', not a dummy object.)
    
    This patch fixes this inconsistency by making any_template_parm_r walk
    into the TREE_TYPE of a dummy object, like it already does for 'this'.
    
            PR c++/103198
    
    gcc/cp/ChangeLog:
    
            * pt.c (any_template_parm_r): Walk the TREE_TYPE of a dummy
            object.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/cpp2a/concepts-this1.C: New test.
    
    (cherry picked from commit 09c24fe42ff2cef3f3291f5a7540a5835c08430c)

Diff:
---
 gcc/cp/pt.c                                 |  5 +++++
 gcc/testsuite/g++.dg/cpp2a/concepts-this1.C | 30 +++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+)

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index c1a60cae697..27016f90ec6 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -10757,6 +10757,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-12-15 19:55 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20211215195531.13D3D385842C@sourceware.org \
    --to=ppalka@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /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).