public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r10-9635] c++: Fix ICE with CTAD in concept [PR98611]
@ 2021-03-31 12:33 Patrick Palka
  0 siblings, 0 replies; only message in thread
From: Patrick Palka @ 2021-03-31 12:33 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:57b0df85b7e4b50198a8d3a09d57c52f0d994ba8

commit r10-9635-g57b0df85b7e4b50198a8d3a09d57c52f0d994ba8
Author: Patrick Palka <ppalka@redhat.com>
Date:   Tue Jan 12 09:34:41 2021 -0500

    c++: Fix ICE with CTAD in concept [PR98611]
    
    This patch teaches cp_walk_subtrees to visit the template represented
    by a CTAD placeholder, which would otherwise be not visited during
    find_template_parameters.  The template may be a template template
    parameter (as in the first testcase), or it may implicitly use the
    template parameters of an enclosing class template (as in the second
    testcase), and in either case we need to visit this tree to record the
    template parameters used therein for later satisfaction.
    
    gcc/cp/ChangeLog:
    
            PR c++/98611
            * tree.c (cp_walk_subtrees) <case TEMPLATE_TYPE_PARM>: Visit
            the template of a CTAD placeholder.
    
    gcc/testsuite/ChangeLog:
    
            PR c++/98611
            * g++.dg/cpp2a/concepts-ctad1.C: New test.
            * g++.dg/cpp2a/concepts-ctad2.C: New test.
    
    (cherry picked from commit e0bec6ceac47752616dd9fe0801344ed45db2fd3)

Diff:
---
 gcc/cp/tree.c                               |  5 ++++-
 gcc/testsuite/g++.dg/cpp2a/concepts-ctad1.C | 16 ++++++++++++++++
 gcc/testsuite/g++.dg/cpp2a/concepts-ctad2.C | 13 +++++++++++++
 3 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c
index 6dfc1b09f96..b36ca4eddc0 100644
--- a/gcc/cp/tree.c
+++ b/gcc/cp/tree.c
@@ -5064,12 +5064,15 @@ cp_walk_subtrees (tree *tp, int *walk_subtrees_p, walk_tree_fn func,
   result = NULL_TREE;
   switch (code)
     {
+    case TEMPLATE_TYPE_PARM:
+      if (template_placeholder_p (*tp))
+	WALK_SUBTREE (CLASS_PLACEHOLDER_TEMPLATE (*tp));
+      /* Fall through.  */
     case DEFERRED_PARSE:
     case TEMPLATE_TEMPLATE_PARM:
     case BOUND_TEMPLATE_TEMPLATE_PARM:
     case UNBOUND_CLASS_TEMPLATE:
     case TEMPLATE_PARM_INDEX:
-    case TEMPLATE_TYPE_PARM:
     case TYPENAME_TYPE:
     case TYPEOF_TYPE:
     case UNDERLYING_TYPE:
diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-ctad1.C b/gcc/testsuite/g++.dg/cpp2a/concepts-ctad1.C
new file mode 100644
index 00000000000..ec2e4b014d7
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/concepts-ctad1.C
@@ -0,0 +1,16 @@
+// PR c++/98611
+// { dg-do compile { target c++20 } }
+
+template <class T, class U>
+concept IsSame = __is_same(T, U);
+
+template <class T, template <class...> class _Class>
+concept IsInstantiationOf = requires(T object) {
+ { _Class{object} } -> IsSame<T>;
+};
+
+template <class T> struct Degrees {};
+static_assert(IsInstantiationOf<Degrees<int>, Degrees>);
+
+template <class T> struct NotDegrees {};
+static_assert(!IsInstantiationOf<Degrees<int>, NotDegrees>);
diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-ctad2.C b/gcc/testsuite/g++.dg/cpp2a/concepts-ctad2.C
new file mode 100644
index 00000000000..0d7f9790777
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/concepts-ctad2.C
@@ -0,0 +1,13 @@
+// PR c++/98611
+// { dg-do compile { target c++20 } }
+
+template <class>
+struct S {
+  template <class T> struct Tmpl { Tmpl(T); };
+
+  template <class T>
+    requires requires (T object) { Tmpl{object}; }
+  static int f(T);
+};
+
+int a = S<int>::f(0);


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

only message in thread, other threads:[~2021-03-31 12:33 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-31 12:33 [gcc r10-9635] c++: Fix ICE with CTAD in concept [PR98611] Patrick Palka

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