From: Patrick Palka Date: Fri, 17 May 2024 13:02:52 +0000 (-0400) Subject: c++: aggregate CTAD w/ paren init and bases [PR115114] X-Git-Tag: basepoints/gcc-16~8923 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5aaf47cb1987bbc5508c4b9b7dad5ea7d69af2c2;p=thirdparty%2Fgcc.git 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 --- diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 32640f8e946..e77c48e463e 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -30200,6 +30200,13 @@ maybe_aggr_guide (tree tmpl, tree init, vec *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 00000000000..16dc0f52b64 --- /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 +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; + +template +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;