When instantiating a partial specialization of a template member function for a full specialization of a class template, we test whether the context of variables local to the partial specialization, i.e., the partial specialization itself, is dependent, and this ICEs in type_dependent_expression_p, when checking that the function type isn't type-dependent because it is not in a type-dependent scope.
We shouldn't have got that far: the previous block in type_dependent_expression_p catches cases in which the function itself takes template arguments of its own, but it only did so for primary templates, not for partial specializations. This patch fixes that. Regstrapped on x86_64- and i686-linux-gnu. Ok to install? for gcc/cp/ChangeLog PR c++/87770 * pt.c (type_dependent_expression_p): Check partial specializations for taking template arguments. for gcc/testsuite/ChangeLog PR c++/87770 * g++.dg/pr87770.C: New. --- gcc/cp/pt.c | 3 ++- gcc/testsuite/g++.dg/pr87770.C | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/pr87770.C diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index e4f76478f543..fb8993f1959e 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -25607,7 +25607,8 @@ type_dependent_expression_p (tree expression) that come from the template-id; the template arguments for the enclosing class do not make it type-dependent unless they are used in the type of the decl. */ - if (PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (expression)) + if ((PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (expression)) + || DECL_TEMPLATE_SPECIALIZATION (DECL_TI_TEMPLATE (expression))) && (any_dependent_template_arguments_p (INNERMOST_TEMPLATE_ARGS (DECL_TI_ARGS (expression))))) return true; diff --git a/gcc/testsuite/g++.dg/pr87770.C b/gcc/testsuite/g++.dg/pr87770.C new file mode 100644 index 000000000000..69eff4a786fe --- /dev/null +++ b/gcc/testsuite/g++.dg/pr87770.C @@ -0,0 +1,11 @@ +// { dg-do compile } + +template <typename> struct d { + template <typename e> d(e); +}; +template <> template <typename e> d<int>::d(e); +template <> template <typename e> d<int>::d(e) { + long g; + (void)g; +} +template d<int>::d(char); -- Alexandre Oliva, freedom fighter https://FSFLA.org/blogs/lxo Be the change, be Free! FSF Latin America board member GNU Toolchain Engineer Free Software Evangelist Hay que enGNUrecerse, pero sin perder la terGNUra jamás-GNUChe