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 <jason@redhat.com>
pull/91/merge
Patrick Palka 2024-05-17 09:02:52 -04:00
parent c9e05b03c1
commit 5aaf47cb19
2 changed files with 30 additions and 0 deletions

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

View File

@ -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>;