if (subargs != error_mark_node
&& !any_dependent_template_arguments_p (subargs))
{
- elem = TREE_TYPE (instantiate_template (fn, subargs, tf_none));
+ fn = instantiate_template (fn, subargs, tf_none);
+ if (!constraints_satisfied_p (fn))
+ continue;
+
+ elem = TREE_TYPE (fn);
if (try_one_overload (tparms, targs, tempargs, parm,
elem, strict, sub_strict, addr_p, explain_p)
&& (!goodfn || !same_type_p (goodfn, elem)))
badfn = fn;
badargs = subargs;
}
- else if (elem && (!goodfn || !decls_match (goodfn, elem)))
+ else if (elem && (!goodfn || !decls_match (goodfn, elem))
+ && constraints_satisfied_p (elem))
{
goodfn = elem;
++good;
--- /dev/null
+// Verify we check associated constraints when resolving the address of a
+// template-id.
+// { dg-do compile { target c++20 } }
+
+void id(auto) { }
+
+template <typename>
+int f() { return 0; }
+
+template <typename T> requires requires { T::fail(); }
+auto f() { T::fail(); }
+
+int main() {
+ using U = decltype(&f<int>);
+ (void)&f<int>;
+ id(&f<int>);
+}