If we are missing some earlier template arguments, we need to be prepared for template parameters to remain in the result of substitution. In such a situation we need to make sure processing_template_decl is set so things don't get confused by those template parameters.
Tested x86_64-pc-linux-gnu, applying to trunk/7/6.
commit c7c6394b812ab2dcdace68d637c516ea3fb2a5f5 Author: Jason Merrill <ja...@redhat.com> Date: Fri Mar 9 17:40:39 2018 -0500 PR c++/84785 - ICE with alias template and default targs. * pt.c (type_unification_real): Set processing_template_decl if saw_undeduced == 1. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 89024c10fe2..2d7ce6062a7 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -19977,7 +19977,13 @@ type_unification_real (tree tparms, location_t save_loc = input_location; if (DECL_P (parm)) input_location = DECL_SOURCE_LOCATION (parm); + + if (saw_undeduced == 1) + ++processing_template_decl; arg = tsubst_template_arg (arg, full_targs, fcomplain, NULL_TREE); + if (saw_undeduced == 1) + --processing_template_decl; + if (arg != error_mark_node && !uses_template_parms (arg)) arg = convert_template_argument (parm, arg, full_targs, complain, i, NULL_TREE); diff --git a/gcc/testsuite/g++.dg/cpp0x/alias-decl-63.C b/gcc/testsuite/g++.dg/cpp0x/alias-decl-63.C new file mode 100644 index 00000000000..04fb42d9e09 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/alias-decl-63.C @@ -0,0 +1,18 @@ +// PR c++/84785 +// { dg-do compile { target c++11 } } + +template <typename> struct A; +template <bool> struct B; +template <bool B, typename> using enable_if_t = typename B<B>::type; +template <long> using type_pack_element = int; +struct variant { + variant() {} + template <typename Arg, long I = Arg::type::value, + typename = type_pack_element<I>, enable_if_t<A<Arg>::value, int>> + variant(Arg &&); +}; + +struct S { + variant var; +}; +int main() { S s; }