]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: excessive satisfaction in check_methods [PR108579]
authorPatrick Palka <ppalka@redhat.com>
Fri, 3 Feb 2023 14:12:31 +0000 (09:12 -0500)
committerPatrick Palka <ppalka@redhat.com>
Fri, 3 Feb 2023 14:12:31 +0000 (09:12 -0500)
In check_methods we're unnecessarily checking satisfaction for all
constructors and assignment operators, even those that don't look like
copy/move special members.  In the testcase below this manifests as an
unstable satisfaction error because the satisfaction result is first
determined to be false during check_methods (since A<int> is incomplete
at this point) and later true after completion of A<int>.

This patch fixes this simply by swapping the order of the
constraint_satisfied_p and copy/move_fn_p tests.

PR c++/108579

gcc/cp/ChangeLog:

* class.cc (check_methods): Swap order of constraints_satisfied_p
and copy/move_fn_p tests.

gcc/testsuite/ChangeLog:

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

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

index a2aa6674590b5536af1df2edb8692d2f4ac3e3ec..40e6b7365a8a2997e2e72c4265bbdf82b4f8f1e0 100644 (file)
@@ -4822,11 +4822,11 @@ check_methods (tree t)
        /* Might be trivial.  */;
       else if (TREE_CODE (fn) == TEMPLATE_DECL)
        /* Templates are never special members.  */;
-      else if (!constraints_satisfied_p (fn))
-       /* Not eligible.  */;
-      else if (copy_fn_p (fn))
+      else if (copy_fn_p (fn)
+              && constraints_satisfied_p (fn))
        TYPE_HAS_COMPLEX_COPY_CTOR (t) = true;
-      else if (move_fn_p (fn))
+      else if (move_fn_p (fn)
+              && constraints_satisfied_p (fn))
        TYPE_HAS_COMPLEX_MOVE_CTOR (t) = true;
     }
 
@@ -4836,11 +4836,11 @@ check_methods (tree t)
        /* Might be trivial.  */;
       else if (TREE_CODE (fn) == TEMPLATE_DECL)
        /* Templates are never special members.  */;
-      else if (!constraints_satisfied_p (fn))
-       /* Not eligible.  */;
-      else if (copy_fn_p (fn))
+      else if (copy_fn_p (fn)
+              && constraints_satisfied_p (fn))
        TYPE_HAS_COMPLEX_COPY_ASSIGN (t) = true;
-      else if (move_fn_p (fn))
+      else if (move_fn_p (fn)
+              && constraints_satisfied_p (fn))
        TYPE_HAS_COMPLEX_MOVE_ASSIGN (t) = true;
     }
 }
diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-pr108579.C b/gcc/testsuite/g++.dg/cpp2a/concepts-pr108579.C
new file mode 100644 (file)
index 0000000..f8721f0
--- /dev/null
@@ -0,0 +1,14 @@
+// PR c++/108579
+// { dg-do compile { target c++20 } }
+
+template<class T>
+struct A {
+  A(double, char);
+  A(int) requires requires { A(0.0, 'c'); };
+  A& operator=(int) requires requires { A(1.0, 'd'); };
+};
+
+int main() {
+  A<int> a(3);
+  a = 5;
+}