@@ -23304,6 +23304,7 @@ type_unification_real (tree tparms,
might be instantiation-dependent like access (87480). */
processing_template_decl_sentinel s (!any_dependent_targs);
tree substed = NULL_TREE;
+ tristate dependent_p = tristate::unknown ();
if (saw_undeduced == 1 && !any_dependent_targs)
{
/* First instatiate in template context, in case we still
@@ -23312,8 +23313,9 @@ type_unification_real (tree tparms,
substed = tsubst_template_arg (arg, full_targs, complain,
NULL_TREE);
--processing_template_decl;
+ dependent_p = uses_template_parms (substed);
if (substed != error_mark_node
- && !uses_template_parms (substed))
+ && dependent_p.is_false ())
/* We replaced all the tparms, substitute again out of
template context. */
substed = NULL_TREE;
@@ -23321,8 +23323,11 @@ type_unification_real (tree tparms,
if (!substed)
substed = tsubst_template_arg (arg, full_targs, complain,
NULL_TREE);
+ if (dependent_p.is_unknown ())
+ dependent_p = (processing_template_decl
+ && uses_template_parms (substed));
- if (!uses_template_parms (substed))
+ if (dependent_p.is_false ())
arg = convert_template_argument (parm, substed, full_targs,
complain, i, NULL_TREE);
else if (saw_undeduced == 1)
new file mode 100644
@@ -0,0 +1,24 @@
+// PR c++/101463
+// { dg-do compile { target c++17 } }
+
+int a;
+
+int& v = a;
+
+template<const int& = v>
+void f(int) { }
+
+template<class T, int& = v>
+void g(T) { }
+
+template<class T>
+int& vt = a;
+
+template<class T, int& = vt<T>>
+void h(T) { }
+
+int main() {
+ f(0);
+ g(0);
+ h(0);
+}
new file mode 100644
@@ -0,0 +1,25 @@
+// PR c++/101463
+// A version of nontype6.C where v and vt are constexpr.
+// { dg-do compile { target c++17 } }
+
+int a;
+
+constexpr int& v = a;
+
+template<const int& = v>
+void f(int) { }
+
+template<class T, const int& = v>
+void g(T) { }
+
+template<class T>
+constexpr int& vt = a;
+
+template<class T, const int& = vt<T>>
+void h(T) { }
+
+int main() {
+ f(0);
+ g(0);
+ h(0);
+}