c++: constraints and address of template-id
authorPatrick Palka <ppalka@redhat.com>
Mon, 10 Aug 2020 13:33:17 +0000 (09:33 -0400)
committerPatrick Palka <ppalka@redhat.com>
Mon, 10 Aug 2020 13:33:17 +0000 (09:33 -0400)
When resolving the address of a template-id, we need to drop functions
whose associated constraints are not satisfied, as per [over.over].  We
do so in resolve_address_of_overloaded_function, but not in
resolve_overloaded_unification or resolve_nondeduced_context, which
seems like an oversight.

gcc/cp/ChangeLog:

* pt.c (resolve_overloaded_unification): Drop functions with
unsatisfied constraints.
(resolve_nondeduced_context): Likewise.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/concepts-fn5.C: New test.
* g++.dg/concepts/fn8.C: Generalize dg-error directive to accept
"no matching function ..." diagnostic.
* g++.dg/cpp2a/concepts-fn1.C: Likewise.
* g++.dg/cpp2a/concepts-ts2.C: Likewise.
* g++.dg/cpp2a/concepts-ts3.C: Likewise.

gcc/cp/pt.c
gcc/testsuite/g++.dg/concepts/fn8.C
gcc/testsuite/g++.dg/cpp2a/concepts-fn1.C
gcc/testsuite/g++.dg/cpp2a/concepts-fn5.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/concepts-ts2.C
gcc/testsuite/g++.dg/cpp2a/concepts-ts3.C

index cff2db4a07eeb61febeefa83a2c46eda4009db6e..cb81d8e9229bb41518d9b8b077c08d85bb6dafd7 100644 (file)
@@ -22122,6 +22122,8 @@ resolve_overloaded_unification (tree tparms,
              && !any_dependent_template_arguments_p (subargs))
            {
              fn = instantiate_template (fn, subargs, tf_none);
+             if (!constraints_satisfied_p (fn))
+               continue;
              if (undeduced_auto_decl (fn))
                {
                  /* Instantiate the function to deduce its return type.  */
@@ -22268,7 +22270,8 @@ resolve_nondeduced_context (tree orig_expr, tsubst_flags_t complain)
                  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;
index ed9008099087ef2e473551507df6715c1bcdab4f..32df5a556c0f01aa7af2ea8c02ba540ed5779a9a 100644 (file)
@@ -24,5 +24,5 @@ template<typename T>
   void g(T x) { }
 
 int main () {
-  g(&f<int>); // { dg-error "no matches" }
+  g(&f<int>); // { dg-error "no match" }
 }
index 238eb819e909108ff45716dc429a4296e1fa3f12..b31675d255ca1f8291d9e2c930bac1354dbadf66 100644 (file)
@@ -170,7 +170,7 @@ template<typename T> void g(T x) { }
 void driver_3 () 
 {
   g(&ok<int>);
-  g(&err<int>); // { dg-error "no matches" }
+  g(&err<int>); // { dg-error "no match" }
 }
 
 
diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-fn5.C b/gcc/testsuite/g++.dg/cpp2a/concepts-fn5.C
new file mode 100644 (file)
index 0000000..8f00a76
--- /dev/null
@@ -0,0 +1,17 @@
+// 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>);
+}
index d28002c035ad73e0e615d6fb63743a8118a10b47..5942ff19327ce1074774dda5b97f194ae3736296 100644 (file)
@@ -173,7 +173,7 @@ template<typename T> void g(T x) { }
 void driver_3 () 
 {
   g(&ok<int>);
-  g(&err<int>); // { dg-error "no matches" }
+  g(&err<int>); // { dg-error "no match" }
 }
 
 
index 9d47a7a083d05b86fe8cee2b46550632c5442d8b..6f7ed1ffee4671342a6b393537026e92b528e511 100644 (file)
@@ -173,7 +173,7 @@ template<typename T> void g(T x) { }
 void driver_3 () 
 {
   g(&ok<int>);
-  g(&err<int>); // { dg-error "no matches" }
+  g(&err<int>); // { dg-error "no match" }
 }