public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++: paren aggr CTAD with base classes [PR115114]
@ 2024-05-16 15:32 Patrick Palka
  2024-05-16 19:37 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Patrick Palka @ 2024-05-16 15:32 UTC (permalink / raw)
  To: gcc-patches; +Cc: jason, Patrick Palka

Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look
OK for trunk and perhaps 14?

-- >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>;
-- 
2.45.1.190.g19fe900cfc


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] c++: paren aggr CTAD with base classes [PR115114]
  2024-05-16 15:32 [PATCH] c++: paren aggr CTAD with base classes [PR115114] Patrick Palka
@ 2024-05-16 19:37 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2024-05-16 19:37 UTC (permalink / raw)
  To: Patrick Palka, gcc-patches

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-05-16 19:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-16 15:32 [PATCH] c++: paren aggr CTAD with base classes [PR115114] Patrick Palka
2024-05-16 19:37 ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).