* [PATCH] c++: fix alias CTAD [PR114377] @ 2024-03-25 15:17 centurion 2024-03-26 10:04 ` centurion ` (2 more replies) 0 siblings, 3 replies; 6+ messages in thread From: centurion @ 2024-03-25 15:17 UTC (permalink / raw) To: gcc-patches From b34312d82b236601c348382d30e625558f37d40c Mon Sep 17 00:00:00 2001 From: centurion <centurion009@proton.me> Date: Mon, 25 Mar 2024 01:57:21 +0400 Subject: [PATCH] c++: fix alias CTAD [PR114377] PR c++/114377 gcc/cp/ChangeLog: PR c++/114377 * pt.cc (find_template_parameter_info::found): Use TREE_TYPE for TEMPLATE_DECL instead of DECL_INITIAL. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/class-deduction-alias19.C: New test. --- gcc/cp/pt.cc | 3 ++- .../g++.dg/cpp2a/class-deduction-alias19.C | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/class-deduction-alias19.C diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 8cf0d5b7a8d..d8a02f1cd7f 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -11032,7 +11032,8 @@ find_template_parameter_info::found (tree parm) { if (TREE_CODE (parm) == TREE_LIST) parm = TREE_VALUE (parm); - if (TREE_CODE (parm) == TYPE_DECL) + if (TREE_CODE (parm) == TYPE_DECL + || TREE_CODE(parm) == TEMPLATE_DECL) parm = TREE_TYPE (parm); else parm = DECL_INITIAL (parm); diff --git a/gcc/testsuite/g++.dg/cpp2a/class-deduction-alias19.C b/gcc/testsuite/g++.dg/cpp2a/class-deduction-alias19.C new file mode 100644 index 00000000000..1ea79bd7691 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/class-deduction-alias19.C @@ -0,0 +1,15 @@ +// PR c++/114377 +// { dg-do compile { target c++20 } } + +template <template <typename> typename Iterator> +struct K {}; + +template <typename C, typename IteratorPolicy> +class Foo {}; + +template <typename C, template<typename> typename TTP> +using Bar = Foo<C, K<TTP>>; + +void s() { + Bar(1); // { dg-error "failed|no match" } +} -- 2.44.0 ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] c++: fix alias CTAD [PR114377] 2024-03-25 15:17 [PATCH] c++: fix alias CTAD [PR114377] centurion @ 2024-03-26 10:04 ` centurion 2024-03-26 10:05 ` centurion 2024-03-27 14:21 ` Patrick Palka 2 siblings, 0 replies; 6+ messages in thread From: centurion @ 2024-03-26 10:04 UTC (permalink / raw) To: gcc-patches The problem was that in cp/pt.cc:find_template_parameter_info::found compiler tried to get TEMPLATE_TEMPLATE_PARM tree from TEMPLATE_DECL tree by DECL_INITIAL instead of TREE_TYPE(like for TYPE_DECL).Therefore, parm got nullptr, because cp/pt.cc:process_template_parm doesn't assign anything to DECL_INITIAL for both TYPE_DECL and TEMPLATE_DECL. On Monday, March 25th, 2024 at 7:17 PM, centurion <centurion009@proton.me> wrote: > From b34312d82b236601c348382d30e625558f37d40c Mon Sep 17 00:00:00 2001 > From: centurion centurion009@proton.me > > Date: Mon, 25 Mar 2024 01:57:21 +0400 > Subject: [PATCH] c++: fix alias CTAD [PR114377] > > PR c++/114377 > > gcc/cp/ChangeLog: > > PR c++/114377 > * pt.cc (find_template_parameter_info::found): Use TREE_TYPE for > TEMPLATE_DECL instead of DECL_INITIAL. > > gcc/testsuite/ChangeLog: > > * g++.dg/cpp2a/class-deduction-alias19.C: New test. > --- > gcc/cp/pt.cc | 3 ++- > .../g++.dg/cpp2a/class-deduction-alias19.C | 15 +++++++++++++++ > 2 files changed, 17 insertions(+), 1 deletion(-) > create mode 100644 gcc/testsuite/g++.dg/cpp2a/class-deduction-alias19.C > > diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc > index 8cf0d5b7a8d..d8a02f1cd7f 100644 > --- a/gcc/cp/pt.cc > +++ b/gcc/cp/pt.cc > @@ -11032,7 +11032,8 @@ find_template_parameter_info::found (tree parm) > { > if (TREE_CODE (parm) == TREE_LIST) > parm = TREE_VALUE (parm); > - if (TREE_CODE (parm) == TYPE_DECL) > + if (TREE_CODE (parm) == TYPE_DECL > + || TREE_CODE(parm) == TEMPLATE_DECL) > parm = TREE_TYPE (parm); > else > parm = DECL_INITIAL (parm); > diff --git a/gcc/testsuite/g++.dg/cpp2a/class-deduction-alias19.C b/gcc/testsuite/g++.dg/cpp2a/class-deduction-alias19.C > new file mode 100644 > index 00000000000..1ea79bd7691 > --- /dev/null > +++ b/gcc/testsuite/g++.dg/cpp2a/class-deduction-alias19.C > @@ -0,0 +1,15 @@ > +// PR c++/114377 > +// { dg-do compile { target c++20 } } > + > +template <template <typename> typename Iterator> > > +struct K {}; > + > +template <typename C, typename IteratorPolicy> > > +class Foo {}; > + > +template <typename C, template<typename> typename TTP> > > +using Bar = Foo<C, K<TTP>>; > > + > +void s() { > + Bar(1); // { dg-error "failed|no match" } > +} > -- > 2.44.0 ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] c++: fix alias CTAD [PR114377] 2024-03-25 15:17 [PATCH] c++: fix alias CTAD [PR114377] centurion 2024-03-26 10:04 ` centurion @ 2024-03-26 10:05 ` centurion 2024-03-27 14:21 ` Patrick Palka 2 siblings, 0 replies; 6+ messages in thread From: centurion @ 2024-03-26 10:05 UTC (permalink / raw) To: gcc-patches The problem was is that in cp/pt.cc:find_template_parameter_info::found compiler tried to get TEMPLATE_TEMPLATE_PARM tree from TEMPLATE_DECL tree by DECL_INITIAL instead of TREE_TYPE(like for TYPE_DECL). Therefore, parm got nullptr, because cp/pt.cc:process_template_parm doesn't assign anything to DECL_INITIAL for both TYPE_DECL and TEMPLATE_DECL. On Monday, March 25th, 2024 at 7:17 PM, centurion <centurion009@proton.me> wrote: > From b34312d82b236601c348382d30e625558f37d40c Mon Sep 17 00:00:00 2001 > From: centurion centurion009@proton.me > > Date: Mon, 25 Mar 2024 01:57:21 +0400 > Subject: [PATCH] c++: fix alias CTAD [PR114377] > > PR c++/114377 > > gcc/cp/ChangeLog: > > PR c++/114377 > * pt.cc (find_template_parameter_info::found): Use TREE_TYPE for > TEMPLATE_DECL instead of DECL_INITIAL. > > gcc/testsuite/ChangeLog: > > * g++.dg/cpp2a/class-deduction-alias19.C: New test. > --- > gcc/cp/pt.cc | 3 ++- > .../g++.dg/cpp2a/class-deduction-alias19.C | 15 +++++++++++++++ > 2 files changed, 17 insertions(+), 1 deletion(-) > create mode 100644 gcc/testsuite/g++.dg/cpp2a/class-deduction-alias19.C > > diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc > index 8cf0d5b7a8d..d8a02f1cd7f 100644 > --- a/gcc/cp/pt.cc > +++ b/gcc/cp/pt.cc > @@ -11032,7 +11032,8 @@ find_template_parameter_info::found (tree parm) > { > if (TREE_CODE (parm) == TREE_LIST) > parm = TREE_VALUE (parm); > - if (TREE_CODE (parm) == TYPE_DECL) > + if (TREE_CODE (parm) == TYPE_DECL > + || TREE_CODE(parm) == TEMPLATE_DECL) > parm = TREE_TYPE (parm); > else > parm = DECL_INITIAL (parm); > diff --git a/gcc/testsuite/g++.dg/cpp2a/class-deduction-alias19.C b/gcc/testsuite/g++.dg/cpp2a/class-deduction-alias19.C > new file mode 100644 > index 00000000000..1ea79bd7691 > --- /dev/null > +++ b/gcc/testsuite/g++.dg/cpp2a/class-deduction-alias19.C > @@ -0,0 +1,15 @@ > +// PR c++/114377 > +// { dg-do compile { target c++20 } } > + > +template <template <typename> typename Iterator> > > +struct K {}; > + > +template <typename C, typename IteratorPolicy> > > +class Foo {}; > + > +template <typename C, template<typename> typename TTP> > > +using Bar = Foo<C, K<TTP>>; > > + > +void s() { > + Bar(1); // { dg-error "failed|no match" } > +} > -- > 2.44.0 ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] c++: fix alias CTAD [PR114377] 2024-03-25 15:17 [PATCH] c++: fix alias CTAD [PR114377] centurion 2024-03-26 10:04 ` centurion 2024-03-26 10:05 ` centurion @ 2024-03-27 14:21 ` Patrick Palka 2024-03-27 18:36 ` centurion 2 siblings, 1 reply; 6+ messages in thread From: Patrick Palka @ 2024-03-27 14:21 UTC (permalink / raw) To: centurion; +Cc: gcc-patches, jason On Mon, 25 Mar 2024, centurion wrote: > From b34312d82b236601c348382d30e625558f37d40c Mon Sep 17 00:00:00 2001 > From: centurion <centurion009@proton.me> > Date: Mon, 25 Mar 2024 01:57:21 +0400 > Subject: [PATCH] c++: fix alias CTAD [PR114377] > > PR c++/114377 > > gcc/cp/ChangeLog: > > PR c++/114377 > * pt.cc (find_template_parameter_info::found): Use TREE_TYPE for > TEMPLATE_DECL instead of DECL_INITIAL. Makes sense, this is consistent with e.g. template_parm_to_arg. LGTM! > > gcc/testsuite/ChangeLog: > > * g++.dg/cpp2a/class-deduction-alias19.C: New test. > --- > gcc/cp/pt.cc | 3 ++- > .../g++.dg/cpp2a/class-deduction-alias19.C | 15 +++++++++++++++ > 2 files changed, 17 insertions(+), 1 deletion(-) > create mode 100644 gcc/testsuite/g++.dg/cpp2a/class-deduction-alias19.C > > diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc > index 8cf0d5b7a8d..d8a02f1cd7f 100644 > --- a/gcc/cp/pt.cc > +++ b/gcc/cp/pt.cc > @@ -11032,7 +11032,8 @@ find_template_parameter_info::found (tree parm) > { > if (TREE_CODE (parm) == TREE_LIST) > parm = TREE_VALUE (parm); > - if (TREE_CODE (parm) == TYPE_DECL) > + if (TREE_CODE (parm) == TYPE_DECL > + || TREE_CODE(parm) == TEMPLATE_DECL) Style note: there should be a space before the ( of a function/macro call > parm = TREE_TYPE (parm); > else > parm = DECL_INITIAL (parm); > diff --git a/gcc/testsuite/g++.dg/cpp2a/class-deduction-alias19.C b/gcc/testsuite/g++.dg/cpp2a/class-deduction-alias19.C > new file mode 100644 > index 00000000000..1ea79bd7691 > --- /dev/null > +++ b/gcc/testsuite/g++.dg/cpp2a/class-deduction-alias19.C > @@ -0,0 +1,15 @@ > +// PR c++/114377 > +// { dg-do compile { target c++20 } } > + > +template <template <typename> typename Iterator> > +struct K {}; > + > +template <typename C, typename IteratorPolicy> > +class Foo {}; > + > +template <typename C, template<typename> typename TTP> > +using Bar = Foo<C, K<TTP>>; > + > +void s() { > + Bar(1); // { dg-error "failed|no match" } > +} > -- > 2.44.0 > > > ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] c++: fix alias CTAD [PR114377] 2024-03-27 14:21 ` Patrick Palka @ 2024-03-27 18:36 ` centurion 2024-04-04 21:21 ` Jason Merrill 0 siblings, 1 reply; 6+ messages in thread From: centurion @ 2024-03-27 18:36 UTC (permalink / raw) To: Patrick Palka; +Cc: gcc-patches, jason From 22056e95bde82b1dc45b8b611be4c8d756122b02 Mon Sep 17 00:00:00 2001 From: centurion <centurion009@proton.me> Date: Wed, 27 Mar 2024 22:29:57 +0400 Subject: [PATCH] c++: fix alias CTAD [PR114377] PR c++/114377 gcc/cp/ChangeLog: PR c++/114377 * pt.cc (find_template_parameter_info::found): Use TREE_TYPE for TEMPLATE_DECL instead of DECL_INITIAL. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/class-deduction-alias19.C: New test. --- gcc/cp/pt.cc | 3 ++- .../g++.dg/cpp2a/class-deduction-alias19.C | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/class-deduction-alias19.C diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 7b00a8615d2..1425d6116d0 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -11032,7 +11032,8 @@ find_template_parameter_info::found (tree parm) { if (TREE_CODE (parm) == TREE_LIST) parm = TREE_VALUE (parm); - if (TREE_CODE (parm) == TYPE_DECL) + if (TREE_CODE (parm) == TYPE_DECL + || TREE_CODE (parm) == TEMPLATE_DECL) parm = TREE_TYPE (parm); else parm = DECL_INITIAL (parm); diff --git a/gcc/testsuite/g++.dg/cpp2a/class-deduction-alias19.C b/gcc/testsuite/g++.dg/cpp2a/class-deduction-alias19.C new file mode 100644 index 00000000000..1ea79bd7691 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/class-deduction-alias19.C @@ -0,0 +1,15 @@ +// PR c++/114377 +// { dg-do compile { target c++20 } } + +template <template <typename> typename Iterator> +struct K {}; + +template <typename C, typename IteratorPolicy> +class Foo {}; + +template <typename C, template<typename> typename TTP> +using Bar = Foo<C, K<TTP>>; + +void s() { + Bar(1); // { dg-error "failed|no match" } +} -- 2.44.0 On Wednesday, March 27th, 2024 at 6:21 PM, Patrick Palka <ppalka@redhat.com> wrote: > On Mon, 25 Mar 2024, centurion wrote: > > > From b34312d82b236601c348382d30e625558f37d40c Mon Sep 17 00:00:00 2001 > > From: centurion centurion009@proton.me > > Date: Mon, 25 Mar 2024 01:57:21 +0400 > > Subject: [PATCH] c++: fix alias CTAD [PR114377] > > > > PR c++/114377 > > > > gcc/cp/ChangeLog: > > > > PR c++/114377 > > * pt.cc (find_template_parameter_info::found): Use TREE_TYPE for > > TEMPLATE_DECL instead of DECL_INITIAL. > > > Makes sense, this is consistent with e.g. template_parm_to_arg. LGTM! > > > gcc/testsuite/ChangeLog: > > > > * g++.dg/cpp2a/class-deduction-alias19.C: New test. > > --- > > gcc/cp/pt.cc | 3 ++- > > .../g++.dg/cpp2a/class-deduction-alias19.C | 15 +++++++++++++++ > > 2 files changed, 17 insertions(+), 1 deletion(-) > > create mode 100644 gcc/testsuite/g++.dg/cpp2a/class-deduction-alias19.C > > > > diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc > > index 8cf0d5b7a8d..d8a02f1cd7f 100644 > > --- a/gcc/cp/pt.cc > > +++ b/gcc/cp/pt.cc > > @@ -11032,7 +11032,8 @@ find_template_parameter_info::found (tree parm) > > { > > if (TREE_CODE (parm) == TREE_LIST) > > parm = TREE_VALUE (parm); > > - if (TREE_CODE (parm) == TYPE_DECL) > > + if (TREE_CODE (parm) == TYPE_DECL > > + || TREE_CODE(parm) == TEMPLATE_DECL) > > > Style note: there should be a space before the ( of a function/macro call > > > parm = TREE_TYPE (parm); > > else > > parm = DECL_INITIAL (parm); > > diff --git a/gcc/testsuite/g++.dg/cpp2a/class-deduction-alias19.C b/gcc/testsuite/g++.dg/cpp2a/class-deduction-alias19.C > > new file mode 100644 > > index 00000000000..1ea79bd7691 > > --- /dev/null > > +++ b/gcc/testsuite/g++.dg/cpp2a/class-deduction-alias19.C > > @@ -0,0 +1,15 @@ > > +// PR c++/114377 > > +// { dg-do compile { target c++20 } } > > + > > +template <template <typename> typename Iterator> > > +struct K {}; > > + > > +template <typename C, typename IteratorPolicy> > > +class Foo {}; > > + > > +template <typename C, template<typename> typename TTP> > > +using Bar = Foo<C, K<TTP>>; > > + > > +void s() { > > + Bar(1); // { dg-error "failed|no match" } > > +} > > -- > > 2.44.0 ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] c++: fix alias CTAD [PR114377] 2024-03-27 18:36 ` centurion @ 2024-04-04 21:21 ` Jason Merrill 0 siblings, 0 replies; 6+ messages in thread From: Jason Merrill @ 2024-04-04 21:21 UTC (permalink / raw) To: centurion, Patrick Palka; +Cc: gcc-patches Applied, thanks! BTW, in future please see https://gcc.gnu.org/contribute.html#legal This patch is small enough to not need to worry about copyright, but for larger patches we would. On 3/27/24 14:36, centurion wrote: > > PR c++/114377 > > gcc/cp/ChangeLog: > > PR c++/114377 > * pt.cc (find_template_parameter_info::found): Use TREE_TYPE for > TEMPLATE_DECL instead of DECL_INITIAL. > > gcc/testsuite/ChangeLog: > > * g++.dg/cpp2a/class-deduction-alias19.C: New test. > --- > gcc/cp/pt.cc | 3 ++- > .../g++.dg/cpp2a/class-deduction-alias19.C | 15 +++++++++++++++ > 2 files changed, 17 insertions(+), 1 deletion(-) > create mode 100644 gcc/testsuite/g++.dg/cpp2a/class-deduction-alias19.C > > diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc > index 7b00a8615d2..1425d6116d0 100644 > --- a/gcc/cp/pt.cc > +++ b/gcc/cp/pt.cc > @@ -11032,7 +11032,8 @@ find_template_parameter_info::found (tree parm) > { > if (TREE_CODE (parm) == TREE_LIST) > parm = TREE_VALUE (parm); > - if (TREE_CODE (parm) == TYPE_DECL) > + if (TREE_CODE (parm) == TYPE_DECL > + || TREE_CODE (parm) == TEMPLATE_DECL) > parm = TREE_TYPE (parm); > else > parm = DECL_INITIAL (parm); > diff --git a/gcc/testsuite/g++.dg/cpp2a/class-deduction-alias19.C b/gcc/testsuite/g++.dg/cpp2a/class-deduction-alias19.C > new file mode 100644 > index 00000000000..1ea79bd7691 > --- /dev/null > +++ b/gcc/testsuite/g++.dg/cpp2a/class-deduction-alias19.C > @@ -0,0 +1,15 @@ > +// PR c++/114377 > +// { dg-do compile { target c++20 } } > + > +template <template <typename> typename Iterator> > +struct K {}; > + > +template <typename C, typename IteratorPolicy> > +class Foo {}; > + > +template <typename C, template<typename> typename TTP> > +using Bar = Foo<C, K<TTP>>; > + > +void s() { > + Bar(1); // { dg-error "failed|no match" } > +} ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2024-04-04 21:22 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2024-03-25 15:17 [PATCH] c++: fix alias CTAD [PR114377] centurion 2024-03-26 10:04 ` centurion 2024-03-26 10:05 ` centurion 2024-03-27 14:21 ` Patrick Palka 2024-03-27 18:36 ` centurion 2024-04-04 21:21 ` 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).