https://gcc.gnu.org/g:a9837934203d41c96b5cf05e34f68c0d3311c973
commit r14-10221-ga9837934203d41c96b5cf05e34f68c0d3311c973 Author: Patrick Palka <ppa...@redhat.com> Date: Fri May 17 09:02:52 2024 -0400 c++: aggregate CTAD w/ paren init and bases [PR115114] 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 <ja...@redhat.com> (cherry picked from commit 5aaf47cb1987bbc5508c4b9b7dad5ea7d69af2c2) Diff: --- gcc/cp/pt.cc | 7 +++++++ .../g++.dg/cpp2a/class-deduction-aggr15.C | 23 ++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index b5c494e8d15e..e9882f2a3e0a 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -30205,6 +30205,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 index 000000000000..16dc0f52b64c --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/class-deduction-aggr15.C @@ -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>;