From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1888) id 990C43858D20; Fri, 3 Feb 2023 14:15:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 990C43858D20 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1675433741; bh=yvhaCykWTkvt4nsxuFddLYUvIacX2Y2Etw4dR7P4rKM=; h=From:To:Subject:Date:From; b=hh43Hn0GSUAJINNvwoAXiifZzN9mG6Xop+OLFD3o8MWc+BTIbvVaGwPePJhe7AUHa V8aWTklCYsQqywtBZ8ceUlvclta6iI+pRcUDwcbt1cY8xAxIKPtZgPjOD6SRdxRyzb ZtQ7ZfKh7T3LnSLk7zc5gfjTKsblp1Iu99FxU4CU= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Patrick Palka To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-5682] c++: excessive satisfaction in check_methods [PR108579] X-Act-Checkin: gcc X-Git-Author: Patrick Palka X-Git-Refname: refs/heads/master X-Git-Oldrev: e8109bd87766be88e83fe88a44433dae16358a02 X-Git-Newrev: e7930c6750d03b28d922ebbbace20ba9d8622c6a Message-Id: <20230203141541.990C43858D20@sourceware.org> Date: Fri, 3 Feb 2023 14:15:41 +0000 (GMT) List-Id: https://gcc.gnu.org/g:e7930c6750d03b28d922ebbbace20ba9d8622c6a commit r13-5682-ge7930c6750d03b28d922ebbbace20ba9d8622c6a Author: Patrick Palka Date: Fri Feb 3 09:12:31 2023 -0500 c++: excessive satisfaction in check_methods [PR108579] 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 is incomplete at this point) and later true after completion of A. 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. Diff: --- gcc/cp/class.cc | 16 ++++++++-------- gcc/testsuite/g++.dg/cpp2a/concepts-pr108579.C | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/gcc/cp/class.cc b/gcc/cp/class.cc index a2aa6674590..40e6b7365a8 100644 --- a/gcc/cp/class.cc +++ b/gcc/cp/class.cc @@ -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 index 00000000000..f8721f0ab86 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-pr108579.C @@ -0,0 +1,14 @@ +// PR c++/108579 +// { dg-do compile { target c++20 } } + +template +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 a(3); + a = 5; +}