]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: compound-requirement partial substitution [PR113966]
authorPatrick Palka <ppalka@redhat.com>
Mon, 19 Feb 2024 16:34:45 +0000 (11:34 -0500)
committerPatrick Palka <ppalka@redhat.com>
Mon, 15 Apr 2024 15:31:07 +0000 (11:31 -0400)
When partially substituting a requires-expr, we don't want to perform
any additional checks beyond the substitution itself so as to minimize
checking requirements out of order.  So don't check the return-type-req
of a compound-requirement during partial substitution.  And don't check
the noexcept condition either since we can't do that on templated trees.

PR c++/113966

gcc/cp/ChangeLog:

* constraint.cc (tsubst_compound_requirement): Don't check
the noexcept condition or the return-type-requirement when
partially substituting.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/concepts-friend17.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
(cherry picked from commit 3a6f3354eaaf38b5e6be41e4ebf521d299593a6e)

gcc/cp/constraint.cc
gcc/testsuite/g++.dg/cpp2a/concepts-friend17.C [new file with mode: 0644]

index 971619eabea717819e7183c49afbf13de3e0aa29..83df57dc6fd74a6d23f2b43da78f35f00aff193f 100644 (file)
@@ -2142,7 +2142,8 @@ tsubst_compound_requirement (tree t, tree args, sat_info info)
 
   /* Check the noexcept condition.  */
   bool noexcept_p = COMPOUND_REQ_NOEXCEPT_P (t);
-  if (noexcept_p && !expr_noexcept_p (expr, quiet.complain))
+  if (noexcept_p && !processing_template_decl
+      && !expr_noexcept_p (expr, quiet.complain))
     {
       if (info.diagnose_unsatisfaction_p ())
        inform (loc, "%qE is not %<noexcept%>", expr);
@@ -2156,7 +2157,7 @@ tsubst_compound_requirement (tree t, tree args, sat_info info)
     return error_mark_node;
 
   /* Check expression against the result type.  */
-  if (type)
+  if (type && !processing_template_decl)
     {
       if (tree placeholder = type_uses_auto (type))
        {
diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-friend17.C b/gcc/testsuite/g++.dg/cpp2a/concepts-friend17.C
new file mode 100644 (file)
index 0000000..9b5091f
--- /dev/null
@@ -0,0 +1,15 @@
+// PR c++/113966
+// { dg-do compile { target c++20 } }
+
+template<class T> concept C = T::value;
+
+template<class T>
+struct A {
+  template<class U> requires U::value || requires { { T() } -> C; }
+  friend void f(A, U) { }
+
+  template<class U> requires requires { { g(U()) } noexcept; }
+  friend void f(A, U, U) { }
+};
+
+template struct A<int>;