public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++: excessive satisfaction in check_methods [PR108579]
@ 2023-01-30 19:10 Patrick Palka
  2023-02-02 22:46 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Patrick Palka @ 2023-01-30 19:10 UTC (permalink / raw)
  To: gcc-patches; +Cc: jason, Patrick Palka

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_fn_p / move_fn_p tests.

Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look
OK for trunk?  This doesn't fix the regression completely, since
we get a similar unstable satisfaction error if one of the constrained
members is actually a copy/move special member.  I suppose we need to
rearrange things in finish_struct_1 so that check_methods gets called in
a complete class context?

	PR c++/108579

gcc/cp/ChangeLog:

	* class.cc (check_methods): Test constraints_satisfied_p after
	testing copy_fn_p / move_fn_p instead of beforehand.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp2a/concepts-pr108579.C: New test.
---
 gcc/cp/class.cc                                | 16 ++++++++--------
 gcc/testsuite/g++.dg/cpp2a/concepts-pr108579.C | 14 ++++++++++++++
 2 files changed, 22 insertions(+), 8 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-pr108579.C

diff --git a/gcc/cp/class.cc b/gcc/cp/class.cc
index 351de6c5419..d3ce8532d56 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..bc7d709f889
--- /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<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> x(3);
+  x = 5;
+}
-- 
2.39.1.367.g5cc9858f1b


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] c++: excessive satisfaction in check_methods [PR108579]
  2023-01-30 19:10 [PATCH] c++: excessive satisfaction in check_methods [PR108579] Patrick Palka
@ 2023-02-02 22:46 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2023-02-02 22:46 UTC (permalink / raw)
  To: Patrick Palka, gcc-patches

On 1/30/23 14:10, Patrick Palka wrote:
> 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_fn_p / move_fn_p tests.
> 
> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look
> OK for trunk?  This doesn't fix the regression completely, since
> we get a similar unstable satisfaction error if one of the constrained
> members is actually a copy/move special member.  I suppose we need to
> rearrange things in finish_struct_1 so that check_methods gets called in
> a complete class context?

I think the way to make that work, if indeed that's desirable, would be 
to determine those properties lazily instead of at finish_struct time.

The patch is OK.

> 	PR c++/108579
> 
> gcc/cp/ChangeLog:
> 
> 	* class.cc (check_methods): Test constraints_satisfied_p after
> 	testing copy_fn_p / move_fn_p instead of beforehand.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* g++.dg/cpp2a/concepts-pr108579.C: New test.
> ---
>   gcc/cp/class.cc                                | 16 ++++++++--------
>   gcc/testsuite/g++.dg/cpp2a/concepts-pr108579.C | 14 ++++++++++++++
>   2 files changed, 22 insertions(+), 8 deletions(-)
>   create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-pr108579.C
> 
> diff --git a/gcc/cp/class.cc b/gcc/cp/class.cc
> index 351de6c5419..d3ce8532d56 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..bc7d709f889
> --- /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<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> x(3);
> +  x = 5;
> +}


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-02-02 22:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-30 19:10 [PATCH] c++: excessive satisfaction in check_methods [PR108579] Patrick Palka
2023-02-02 22:46 ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).