From: Jason Merrill Date: Mon, 18 May 2015 18:08:48 +0000 (-0400) Subject: pt.c (tsubst_decl): Call coerce_innermost_template_parms. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=b237c4cbd3da7a266863ed049cbb2ef60b0aaa81;p=gcc.git pt.c (tsubst_decl): Call coerce_innermost_template_parms. * pt.c (tsubst_decl) [VAR_DECL]: Call coerce_innermost_template_parms. (determine_specialization): Call coerce_template_parms. From-SVN: r223304 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 957dc1deed5..04576e5a8a0 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,8 @@ 2015-05-18 Jason Merrill + * pt.c (tsubst_decl) [VAR_DECL]: Call coerce_innermost_template_parms. + (determine_specialization): Call coerce_template_parms. + DR 1391 * pt.c (type_unification_real): Check convertibility here. (unify_one_argument): Not here. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 2cd36c9c9ff..2166f5fb65e 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -1919,7 +1919,13 @@ determine_specialization (tree template_id, ++header_count; if (variable_template_p (fns)) - templates = tree_cons (explicit_targs, fns, templates); + { + tree parms = INNERMOST_TEMPLATE_PARMS (DECL_TEMPLATE_PARMS (fns)); + targs = coerce_template_parms (parms, explicit_targs, fns, + tf_warning_or_error, + /*req_all*/true, /*use_defarg*/true); + templates = tree_cons (targs, fns, templates); + } else for (; fns; fns = OVL_NEXT (fns)) { tree fn = OVL_CURRENT (fns); @@ -11265,6 +11271,11 @@ tsubst_decl (tree t, tree args, tsubst_flags_t complain) tmpl = DECL_TI_TEMPLATE (t); gen_tmpl = most_general_template (tmpl); argvec = tsubst (DECL_TI_ARGS (t), args, complain, in_decl); + if (argvec != error_mark_node) + argvec = (coerce_innermost_template_parms + (DECL_TEMPLATE_PARMS (gen_tmpl), + argvec, t, complain, + /*all*/true, /*defarg*/true)); if (argvec == error_mark_node) RETURN (error_mark_node); hash = hash_tmpl_and_args (gen_tmpl, argvec); diff --git a/gcc/testsuite/g++.dg/cpp1y/var-templ25.C b/gcc/testsuite/g++.dg/cpp1y/var-templ25.C new file mode 100644 index 00000000000..8253eac5cde --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/var-templ25.C @@ -0,0 +1,8 @@ +// { dg-do compile { target c++14 } } + +using fl = float; + +template const int V = 0; +template<> const int V = 42; + +static_assert(V == 42, ""); diff --git a/gcc/testsuite/g++.dg/cpp1y/var-templ26.C b/gcc/testsuite/g++.dg/cpp1y/var-templ26.C new file mode 100644 index 00000000000..9ac077773a8 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/var-templ26.C @@ -0,0 +1,19 @@ +// { dg-do compile { target c++14 } } + +template const int V = 0; +template <> const int V = 42; + +template +struct A +{ + using N = T; +}; + +#define SA(X) static_assert((X),#X) +template +struct B +{ + SA(V::N> == 42); +}; + +B b;