c++: No aggregate CTAD with explicit dguide [PR98802]
authorJason Merrill <jason@redhat.com>
Thu, 4 Feb 2021 02:56:59 +0000 (21:56 -0500)
committerJason Merrill <jason@redhat.com>
Thu, 4 Feb 2021 03:03:40 +0000 (22:03 -0500)
In my implementation of P2082R1 I missed this piece: the aggregate deduction
candidate is not generated if the class has user-written deduction guides.

gcc/cp/ChangeLog:

PR c++/98802
* pt.c (do_class_deduction): No aggregate guide if any_dguides_p.

gcc/testsuite/ChangeLog:

PR c++/98802
* g++.dg/cpp1z/class-deduction78.C: New test.

gcc/cp/pt.c
gcc/testsuite/g++.dg/cpp1z/class-deduction78.C [new file with mode: 0644]

index af7c67af29fcf695dba229d8d4db5107b94a0ce0..3605b67e424edd64eb0748cb3e742d2c900590b8 100644 (file)
@@ -29272,8 +29272,9 @@ do_class_deduction (tree ptype, tree tmpl, tree init,
        }
     }
 
-  if (tree guide = maybe_aggr_guide (tmpl, init, args))
-    cands = lookup_add (guide, cands);
+  if (!any_dguides_p)
+    if (tree guide = maybe_aggr_guide (tmpl, init, args))
+      cands = lookup_add (guide, cands);
 
   tree call = error_mark_node;
 
diff --git a/gcc/testsuite/g++.dg/cpp1z/class-deduction78.C b/gcc/testsuite/g++.dg/cpp1z/class-deduction78.C
new file mode 100644 (file)
index 0000000..6516454
--- /dev/null
@@ -0,0 +1,20 @@
+// PR c++/98802
+// { dg-do compile { target c++17 } }
+
+using size_t = decltype(sizeof(42));
+
+template<typename T, size_t N = 0>
+struct List {
+    T head;
+    List<T, N-1> tail;
+};
+
+template<typename T>
+struct List<T, 0> {};
+
+template<typename T> List(T) -> List<T, 1>;
+template<typename T, size_t N> List(T, List<T, N>) -> List<T, N+1>;
+
+int main() {
+  auto list2 = List{0, List{1, List{2}}};
+}