[PATCH] c++: paren aggr CTAD with base classes [PR115114]
Jason Merrill
jason@redhat.com
Thu May 16 19:37:21 GMT 2024
On 5/16/24 11:32, Patrick Palka wrote:
> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look
> OK for trunk and perhaps 14?
OK for both.
> -- >8 --
>
> We're accidentally ignoring base classes during parenthesized aggregate
> CTAD because the TYPE_FIELDS of a template type doesn't contain bases,
> so we need to consider them separately.
>
> PR c++/115114
>
> gcc/cp/ChangeLog:
>
> * pt.cc (maybe_aggr_guide): Consider base classes in the paren
> init case.
>
> gcc/testsuite/ChangeLog:
>
> * g++.dg/cpp2a/class-deduction-aggr15.C: New test.
> ---
> gcc/cp/pt.cc | 7 ++++++
> .../g++.dg/cpp2a/class-deduction-aggr15.C | 23 +++++++++++++++++++
> 2 files changed, 30 insertions(+)
> create mode 100644 gcc/testsuite/g++.dg/cpp2a/class-deduction-aggr15.C
>
> diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
> index d83f530ac8d..54d74989903 100644
> --- a/gcc/cp/pt.cc
> +++ b/gcc/cp/pt.cc
> @@ -30202,6 +30202,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 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<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>;
More information about the Gcc-patches
mailing list