public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/vendors/redhat/heads/gcc-10-branch)] c++: Lambda in friend of constrained class [PR94645]
@ 2020-04-30 22:08 Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2020-04-30 22:08 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:f9f166251f181ddcee64092d89aecbc1166ca706

commit f9f166251f181ddcee64092d89aecbc1166ca706
Author: Patrick Palka <ppalka@redhat.com>
Date:   Thu Apr 23 17:29:55 2020 -0400

    c++: Lambda in friend of constrained class [PR94645]
    
    In the testcase below, when grokfndecl processes the operator() decl for the
    lambda inside the friend function foo, processing_template_decl is rightly 1,
    but template_class_depth on the lambda's closure type incorrectly returns 0
    instead of 1.
    
    Since processing_template_decl > template_class_depth, this makes grokfndecl
    think that the operator() has its own set of template arguments, and so we
    attach the innermost set of constraints -- those belonging to struct l -- to the
    operator() decl.  We then get confused when checking constraints_satisfied_p on
    the operator() because it doesn't have template information and yet has
    constraints associated with it.
    
    This patch fixes template_class_depth to return the correct template nesting
    level in cases like these, in that when it hits a friend function it walks into
    the DECL_FRIEND_CONTEXT of the friend rather than into the CP_DECL_CONTEXT.
    
    gcc/cp/ChangeLog:
    
            PR c++/94645
            * pt.c (template_class_depth): Walk into the DECL_FRIEND_CONTEXT of a
            friend declaration rather than into its CP_DECL_CONTEXT.
    
    gcc/testsuite/ChangeLog:
    
            PR c++/94645
            * g++.dg/cpp2a/concepts-lambda6.C: New test.

Diff:
---
 gcc/cp/ChangeLog                              |  6 ++++++
 gcc/cp/pt.c                                   |  7 ++++++-
 gcc/testsuite/ChangeLog                       |  5 +++++
 gcc/testsuite/g++.dg/cpp2a/concepts-lambda6.C | 19 +++++++++++++++++++
 4 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index fa150e3462f..6506f288e05 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2020-04-23  Patrick Palka  <ppalka@redhat.com>
+
+	PR c++/94645
+	* pt.c (template_class_depth): Walk into the DECL_FRIEND_CONTEXT of a
+	friend declaration rather than into its CP_DECL_CONTEXT.
+
 2020-04-23 Iain Sandoe <iain@sandoe.co.uk>
 
 	PR c++/94288
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 2fe7b66707c..66308a2d295 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -390,7 +390,12 @@ template_class_depth (tree type)
 	++depth;
 
       if (DECL_P (type))
-	type = CP_DECL_CONTEXT (type);
+	{
+	  if (tree fctx = DECL_FRIEND_CONTEXT (type))
+	    type = fctx;
+	  else
+	    type = CP_DECL_CONTEXT (type);
+	}
       else if (LAMBDA_TYPE_P (type) && LAMBDA_TYPE_EXTRA_SCOPE (type))
 	type = LAMBDA_TYPE_EXTRA_SCOPE (type);
       else
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index f9ab061922e..e0df5bc0a99 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2020-04-23  Patrick Palka  <ppalka@redhat.com>
+
+	PR c++/94645
+	* g++.dg/cpp2a/concepts-lambda6.C: New test.
+
 2019-04-23  Eric Botcazou  <ebotcazou@adacore.com>
 
 	* g++.dg/opt/store-merging-4.C: New test.
diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-lambda6.C b/gcc/testsuite/g++.dg/cpp2a/concepts-lambda6.C
new file mode 100644
index 00000000000..0b7c04562e9
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/concepts-lambda6.C
@@ -0,0 +1,19 @@
+// PR c++/94645
+// { dg-do compile { target concepts } }
+
+struct unordered_map {
+  int cend() const noexcept;
+};
+
+template <typename a> concept HasMapInterface = requires(a t) { t.cend(); };
+
+template <typename Mapper> requires HasMapInterface<decltype(Mapper::map())>
+struct l {
+  friend void foo(l opt) { ([]() {})(); }
+};
+
+struct p {
+  static unordered_map map();
+};
+
+void g(l<p> *y) { foo(*y); }


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-04-30 22:08 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-30 22:08 [gcc(refs/vendors/redhat/heads/gcc-10-branch)] c++: Lambda in friend of constrained class [PR94645] Jakub Jelinek

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).