[PATCH] c++: fix alias CTAD [PR114377]

Patrick Palka ppalka@redhat.com
Wed Mar 27 14:21:45 GMT 2024


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



More information about the Gcc-patches mailing list