diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index eba897fe83df64f7f2a8041f2140dbb3459532d3..00bcb7a5202aad64e82fbe68ce7ea8ede1bda28a 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2013-01-15 Dodji Seketeli <dodji@redhat.com> + + PR c++/55663 + * pt.c (coerce_innermost_template_parms): New static function. + (instantiate_alias_template): Use it here. + 2013-01-09 Jason Merrill <jason@redhat.com> PR c++/55878 diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 773afcc02563cc7af7e5928f2b486e6328187749..8ddc14376a403f5d835846d1400c987cc320cd4e 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -128,6 +128,8 @@ static tree tsubst_initializer_list (tree, tree); static tree get_class_bindings (tree, tree, tree, tree); static tree coerce_template_parms (tree, tree, tree, tsubst_flags_t, bool, bool); +static tree coerce_innermost_template_parms (tree, tree, tree, tsubst_flags_t, + bool, bool); static void tsubst_enum (tree, tree, tree); static tree add_to_template_args (tree, tree); static tree add_outermost_template_args (tree, tree); @@ -6740,6 +6742,61 @@ coerce_template_parms (tree parms, return new_inner_args; } +/* Like coerce_template_parms. If PARMS represents all template + parameters levels, this function returns a vector of vectors + representing all the resulting argument levels. Note that in this + case, only the innermost arguments are coerced because the + outermost ones are supposed to have been coerced already. + + Otherwise, if PARMS represents only (the innermost) vector of + parameters, this function returns a vector containing just the + innermost resulting arguments. */ + +static tree +coerce_innermost_template_parms (tree parms, + tree args, + tree in_decl, + tsubst_flags_t complain, + bool require_all_args, + bool use_default_args) +{ + int parms_depth = TMPL_PARMS_DEPTH (parms); + int args_depth = TMPL_ARGS_DEPTH (args); + tree coerced_args; + + if (parms_depth > 1) + { + coerced_args = make_tree_vec (parms_depth); + tree level; + int cur_depth; + + for (level = parms, cur_depth = parms_depth; + parms_depth > 0 && level != NULL_TREE; + level = TREE_CHAIN (level), --cur_depth) + { + tree l; + if (cur_depth == args_depth) + l = coerce_template_parms (TREE_VALUE (level), + args, in_decl, complain, + require_all_args, + use_default_args); + else + l = TMPL_ARGS_LEVEL (args, cur_depth); + + if (l == error_mark_node) + return error_mark_node; + + SET_TMPL_ARGS_LEVEL (coerced_args, cur_depth, l); + } + } + else + coerced_args = coerce_template_parms (INNERMOST_TEMPLATE_PARMS (parms), + args, in_decl, complain, + require_all_args, + use_default_args); + return coerced_args; +} + /* Returns 1 if template args OT and NT are equivalent. */ static int @@ -14640,6 +14697,13 @@ instantiate_alias_template (tree tmpl, tree args, tsubst_flags_t complain) ggc_free (tinst); return error_mark_node; } + + args = + coerce_innermost_template_parms (DECL_TEMPLATE_PARMS (tmpl), + args, tmpl, complain, + /*require_all_args=*/true, + /*use_default_args=*/true); + tree r = instantiate_template (tmpl, args, complain); pop_tinst_level (); /* We can't free this if a pending_template entry or last_error_tinst_level diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b3dba4969d688c772d547ded67d6387c12a7f62f..26a479b3f52e251e8f537f0cacc1bc2d1e311ac5 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2013-01-15 Dodji Seketeli <dodji@redhat.com> + + PR c++/55663 + * g++.dg/cpp0x/alias-decl-31.C: New test. + 2013-01-15 Paul Thomas <pault@gcc.gnu.org> PR fortran/54286 diff --git a/gcc/testsuite/g++.dg/cpp0x/alias-decl-31.C b/gcc/testsuite/g++.dg/cpp0x/alias-decl-31.C new file mode 100644 index 0000000000000000000000000000000000000000..83eea471d07cc73e643b0826c7acbc66213bee1f --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/alias-decl-31.C @@ -0,0 +1,20 @@ +// Origin: PR c++/55663 +// { dg-do compile { target c++11 } } + +template <typename> +constexpr bool the_truth () { return true; } + +template <bool> + struct Takes_bool { }; + +template<bool B> + using Alias = Takes_bool<B>; + +template<typename T> + struct test { using type = Alias<the_truth<T>()>; }; + +int main () { + test<int> a; + + return 0; +}