diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 0d061adc2ed..beabcc4b027 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -23584,13 +23584,21 @@ unify (tree tparms, tree targs, tree parm, tree arg, int strict, /* We haven't deduced the type of this parameter yet. */ if (cxx_dialect >= cxx17 /* We deduce from array bounds in try_array_deduction. */ - && !(strict & UNIFY_ALLOW_INTEGER)) + && !(strict & UNIFY_ALLOW_INTEGER) + && TEMPLATE_PARM_LEVEL (parm) <= TMPL_ARGS_DEPTH (targs)) { /* Deduce it from the non-type argument. */ tree atype = TREE_TYPE (arg); RECUR_AND_CHECK_FAILURE (tparms, targs, tparm, atype, UNIFY_ALLOW_NONE, explain_p); + /* Now check whether the type of this parameter is still + dependent, and give up if so. */ + ++processing_template_decl; + tparm = tsubst (tparm, targs, tf_none, NULL_TREE); + --processing_template_decl; + if (uses_template_parms (tparm)) + return unify_success (explain_p); } else /* Try again later. */ diff --git a/gcc/testsuite/g++.dg/cpp1z/nontype-auto17.C b/gcc/testsuite/g++.dg/cpp1z/nontype-auto17.C new file mode 100644 index 00000000000..509eb0e98e3 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/nontype-auto17.C @@ -0,0 +1,10 @@ +// { dg-do compile { target c++11 } } + +template struct K { }; + +template int f(K); // { dg-error "void" } +int a = f(K<42>{}); // { dg-error "no match" } + +struct S { using type = void; }; +template int g(K); // { dg-message "deduction" } +int b = g(K<42>{}); // { dg-error "no match" } diff --git a/gcc/testsuite/g++.dg/cpp1z/nontype-auto18.C b/gcc/testsuite/g++.dg/cpp1z/nontype-auto18.C new file mode 100644 index 00000000000..936c841ce31 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/nontype-auto18.C @@ -0,0 +1,7 @@ +// { dg-do compile { target c++11 } } + +template struct K { }; + +struct S { using type = int; }; +template int g(K); +int a = g(K<42>{}); diff --git a/gcc/testsuite/g++.dg/template/partial5.C b/gcc/testsuite/g++.dg/template/partial5.C index a56229770f4..40d8c45b087 100644 --- a/gcc/testsuite/g++.dg/template/partial5.C +++ b/gcc/testsuite/g++.dg/template/partial5.C @@ -14,7 +14,7 @@ template struct Y { }; template -struct Y { }; // { dg-error "" "" { target { ! c++17 } } } +struct Y { }; // { dg-error "" } template diff --git a/gcc/testsuite/g++.dg/template/ttp33.C b/gcc/testsuite/g++.dg/template/ttp33.C new file mode 100644 index 00000000000..cd0de8ca641 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/ttp33.C @@ -0,0 +1,10 @@ +// A slight variation of ttp31.C. +// { dg-do compile { target c++11 } } + +template class TTA, TA... VA> +struct A { }; + +template class TTC, TC... VC> +struct C : A { };