]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: aggregate CTAD w/ paren init and bases [PR115114]
authorPatrick Palka <ppalka@redhat.com>
Fri, 17 May 2024 13:02:52 +0000 (09:02 -0400)
committerPatrick Palka <ppalka@redhat.com>
Fri, 17 May 2024 13:02:52 +0000 (09:02 -0400)
During aggregate CTAD with paren init, we're accidentally overlooking
base classes since TYPE_FIELDS of a template type doesn't contain
corresponding base fields.  So we need to consider them separately.

PR c++/115114

gcc/cp/ChangeLog:

* pt.cc (maybe_aggr_guide): Consider bases in the paren init case.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/class-deduction-aggr15.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
gcc/cp/pt.cc
gcc/testsuite/g++.dg/cpp2a/class-deduction-aggr15.C [new file with mode: 0644]

index 32640f8e946d346f3043326aab3dd850dfe0c7bb..e77c48e463e21209f47727c8b4f2e831d23119a7 100644 (file)
@@ -30200,6 +30200,13 @@ maybe_aggr_guide (tree tmpl, tree init, vec<tree,va_gc> *args)
   else if (TREE_CODE (init) == TREE_LIST)
     {
       int len = list_length (init);
+      for (tree binfo : BINFO_BASE_BINFOS (TYPE_BINFO (template_type)))
+       {
+         if (!len)
+           break;
+         parms = tree_cons (NULL_TREE, BINFO_TYPE (binfo), parms);
+         --len;
+       }
       for (tree field = TYPE_FIELDS (template_type);
           len;
           --len, field = DECL_CHAIN (field))
diff --git a/gcc/testsuite/g++.dg/cpp2a/class-deduction-aggr15.C b/gcc/testsuite/g++.dg/cpp2a/class-deduction-aggr15.C
new file mode 100644 (file)
index 0000000..16dc0f5
--- /dev/null
@@ -0,0 +1,23 @@
+// PR c++/115114
+// { dg-do compile { target c++20 } }
+
+struct X {} x;
+struct Y {} y;
+
+template<class T, class U>
+struct A : T {
+  U m;
+};
+
+using ty1 = decltype(A{x, 42}); // OK
+using ty1 = decltype(A(x, 42)); // OK, used to fail
+using ty1 = A<X, int>;
+
+template<class T, class U = int, class V = int>
+struct B : T, V {
+  U m = 42;
+};
+
+using ty2 = decltype(B{x, y}); // OK
+using ty2 = decltype(B(x, y)); // OK, used to fail
+using ty2 = B<X, int, Y>;