return convert_from_reference (templ);
}
+/* If the set of template parameters PARMS contains a template parameter
+ at the given LEVEL and INDEX, then return this parameter. Otherwise
+ return NULL_TREE. */
+
+static tree
+corresponding_template_parameter (tree parms, int level, int index)
+{
+ while (TMPL_PARMS_DEPTH (parms) > level)
+ parms = TREE_CHAIN (parms);
+
+ if (TMPL_PARMS_DEPTH (parms) != level
+ || TREE_VEC_LENGTH (TREE_VALUE (parms)) <= index)
+ return NULL_TREE;
+
+ tree t = TREE_VALUE (TREE_VEC_ELT (TREE_VALUE (parms), index));
+ /* As in template_parm_to_arg. */
+ if (TREE_CODE (t) == TYPE_DECL || TREE_CODE (t) == TEMPLATE_DECL)
+ t = TREE_TYPE (t);
+ else
+ t = DECL_INITIAL (t);
+
+ gcc_assert (TEMPLATE_PARM_P (t));
+ return t;
+}
+
+/* Return the template parameter from PARMS that positionally corresponds
+ to the template parameter PARM, or else return NULL_TREE. */
+
+static tree
+corresponding_template_parameter (tree parms, tree parm)
+{
+ int level, index;
+ template_parm_level_and_index (parm, &level, &index);
+ return corresponding_template_parameter (parms, level, index);
+}
+
\f
struct pair_fn_data
{
BOUND_TEMPLATE_TEMPLATE_PARM itself. */
t = TREE_TYPE (TEMPLATE_TEMPLATE_PARM_TEMPLATE_DECL (t));
+ /* This template parameter might be an argument to a cached dependent
+ specalization that was formed earlier inside some other template, in
+ which case the parameter is not among the ones that are in-scope.
+ Look in CTX_PARMS to find the corresponding in-scope template
+ parameter, and use it instead. */
+ if (tree in_scope = corresponding_template_parameter (ftpi->ctx_parms, t))
+ t = in_scope;
+
/* Arguments like const T yield parameters like const T. This means that
a template-id like X<T, const T> would yield two distinct parameters:
T and const T. Adjust types to their unqualified versions. */
--- /dev/null
+// PR c++/95310
+// { dg-do compile { target concepts } }
+
+template <class T>
+using iter_reference_t = decltype(*T{});
+
+template <typename F>
+struct result { using type = iter_reference_t<F>; };
+
+template <class Out, const int& N>
+concept indirectly_writable = requires(Out o) { // { dg-bogus "F =" }
+ iter_reference_t<Out>(*o) = N;
+};
+
+const int a = 0;
+static_assert(indirectly_writable<const int*, a>); // { dg-error "assert" }