From de62200f8374e1137b20ea9c85eb690169f43449 Mon Sep 17 00:00:00 2001 From: Alexandre Oliva Date: Wed, 19 Dec 2018 06:51:30 +0000 Subject: [PATCH] [PR87012] canonicalize ref type for tmpl arg When binding an object to a template parameter of reference type, we take the address of the object and dereference that address. The type of the address may still carry (template) typedefs, but verify_unstripped_args_1 rejects such typedefs other than in the top level of template arguments. Canonicalizing the type we want to convert to right after any substitutions or deductions avoids that issue. for gcc/cp/ChangeLog PR c++/87012 * pt.c (convert_template_argument): Canonicalize type after tsubst/deduce. for gcc/testsuite/ChangeLog PR c++/87012 * g++.dg/cpp0x/pr87012.C: New. From-SVN: r267251 --- gcc/cp/ChangeLog | 4 ++++ gcc/cp/pt.c | 3 +++ gcc/testsuite/ChangeLog | 3 +++ gcc/testsuite/g++.dg/cpp0x/pr87012.C | 11 +++++++++++ 4 files changed, 21 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp0x/pr87012.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 0246806c9a7..433793f186f 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2018-12-19 Alexandre Oliva + PR c++/87012 + * pt.c (convert_template_argument): Canonicalize type after + tsubst/deduce. + PR c++/88146 * method.c (do_build_copy_constructor): Guard cvquals init and loop over fields to run for non-inherited ctors only. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 79eef12112f..e99de71ea9e 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -8019,6 +8019,9 @@ convert_template_argument (tree parm, if (invalid_nontype_parm_type_p (t, complain)) return error_mark_node; + if (t != TREE_TYPE (parm)) + t = canonicalize_type_argument (t, complain); + if (!type_dependent_expression_p (orig_arg) && !uses_template_parms (t)) /* We used to call digest_init here. However, digest_init diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index a0d8c9981bc..52f20c1a888 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2018-12-19 Alexandre Oliva + PR c++/87012 + * g++.dg/cpp0x/pr87012.C: New. + PR c++/88146 * g++.dg/cpp0x/inh-ctor32.C: New. diff --git a/gcc/testsuite/g++.dg/cpp0x/pr87012.C b/gcc/testsuite/g++.dg/cpp0x/pr87012.C new file mode 100644 index 00000000000..fd3eea47c39 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/pr87012.C @@ -0,0 +1,11 @@ +// { dg-do compile { target c++11 } } + +template +using ref = T&; + +int x; + +template class T, T> +struct X { }; + +struct Y : X { }; -- 2.30.2