diff mbox series

c++: CWG 2789 and reversed operator candidates

Message ID 20240920184857.720642-1-ppalka@redhat.com
State New
Headers show
Series c++: CWG 2789 and reversed operator candidates | expand

Commit Message

Patrick Palka Sept. 20, 2024, 6:48 p.m. UTC
Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look
OK for trunk?

-- >8 --

As a follow-up to r15-3741-gee3efe06c9c49c, which was only concerned
with usings, it seems we should also compare contexts of a reversed
vs non-reversed (member) candidate during operator overload
resolution.

	DR 2789

gcc/cp/ChangeLog:

	* call.cc (cand_parms_match): Check for matching class contexts
	even in the reversed case.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp2a/concepts-memfun4.C: Adjust expected result
	involving reversed candidate.
---
 gcc/cp/call.cc                                | 11 +++++++----
 gcc/testsuite/g++.dg/cpp2a/concepts-memfun4.C |  6 +++---
 2 files changed, 10 insertions(+), 7 deletions(-)

Comments

Jason Merrill Sept. 20, 2024, 7:27 p.m. UTC | #1
On 9/20/24 8:48 PM, Patrick Palka wrote:
> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look
> OK for trunk?

OK.

> -- >8 --
> 
> As a follow-up to r15-3741-gee3efe06c9c49c, which was only concerned
> with usings, it seems we should also compare contexts of a reversed
> vs non-reversed (member) candidate during operator overload
> resolution.
> 
> 	DR 2789
> 
> gcc/cp/ChangeLog:
> 
> 	* call.cc (cand_parms_match): Check for matching class contexts
> 	even in the reversed case.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* g++.dg/cpp2a/concepts-memfun4.C: Adjust expected result
> 	involving reversed candidate.
> ---
>   gcc/cp/call.cc                                | 11 +++++++----
>   gcc/testsuite/g++.dg/cpp2a/concepts-memfun4.C |  6 +++---
>   2 files changed, 10 insertions(+), 7 deletions(-)
> 
> diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc
> index f2ce50857ec..70783baac24 100644
> --- a/gcc/cp/call.cc
> +++ b/gcc/cp/call.cc
> @@ -12865,10 +12865,6 @@ cand_parms_match (z_candidate *c1, z_candidate *c2, pmatch match_kind)
>   	}
>       }
>   
> -  else if (reversed)
> -    return (reversed_match (c1, c2)
> -	    && reversed_match (c2, c1));
> -
>     tree parms1 = TYPE_ARG_TYPES (TREE_TYPE (fn1));
>     tree parms2 = TYPE_ARG_TYPES (TREE_TYPE (fn2));
>   
> @@ -12880,6 +12876,10 @@ cand_parms_match (z_candidate *c1, z_candidate *c2, pmatch match_kind)
>         if (base1 != base2)
>   	return false;
>   
> +      if (reversed)
> +	return (reversed_match (c1, c2)
> +		&& reversed_match (c2, c1));
> +
>         /* Use object_parms_correspond to simplify comparing iobj/xobj/static
>   	 member functions.  */
>         if (!object_parms_correspond (fn1, fn2, base1))
> @@ -12897,6 +12897,9 @@ cand_parms_match (z_candidate *c1, z_candidate *c2, pmatch match_kind)
>         parms1 = skip_parms (fn1, parms1);
>         parms2 = skip_parms (fn2, parms2);
>       }
> +  else if (reversed)
> +    return (reversed_match (c1, c2)
> +	    && reversed_match (c2, c1));
>     return compparms (parms1, parms2);
>   }
>   
> diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-memfun4.C b/gcc/testsuite/g++.dg/cpp2a/concepts-memfun4.C
> index cf7f13c007d..d849e9129a3 100644
> --- a/gcc/testsuite/g++.dg/cpp2a/concepts-memfun4.C
> +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-memfun4.C
> @@ -91,7 +91,7 @@ namespace N1 {
>   
>     A<> a;
>     B<> b;
> -  // when comparing the A op== to the reversed B op==, we compare them in
> -  // reverse order, so they match, and we choose the more constrained.
> -  static_assert (a == b);
> +  // A op== and B op== are defined in different classes so constraints
> +  // aren't considered, and the tie is broken via reversedness.
> +  static_assert (!(a == b));
>   }
diff mbox series

Patch

diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc
index f2ce50857ec..70783baac24 100644
--- a/gcc/cp/call.cc
+++ b/gcc/cp/call.cc
@@ -12865,10 +12865,6 @@  cand_parms_match (z_candidate *c1, z_candidate *c2, pmatch match_kind)
 	}
     }
 
-  else if (reversed)
-    return (reversed_match (c1, c2)
-	    && reversed_match (c2, c1));
-
   tree parms1 = TYPE_ARG_TYPES (TREE_TYPE (fn1));
   tree parms2 = TYPE_ARG_TYPES (TREE_TYPE (fn2));
 
@@ -12880,6 +12876,10 @@  cand_parms_match (z_candidate *c1, z_candidate *c2, pmatch match_kind)
       if (base1 != base2)
 	return false;
 
+      if (reversed)
+	return (reversed_match (c1, c2)
+		&& reversed_match (c2, c1));
+
       /* Use object_parms_correspond to simplify comparing iobj/xobj/static
 	 member functions.  */
       if (!object_parms_correspond (fn1, fn2, base1))
@@ -12897,6 +12897,9 @@  cand_parms_match (z_candidate *c1, z_candidate *c2, pmatch match_kind)
       parms1 = skip_parms (fn1, parms1);
       parms2 = skip_parms (fn2, parms2);
     }
+  else if (reversed)
+    return (reversed_match (c1, c2)
+	    && reversed_match (c2, c1));
   return compparms (parms1, parms2);
 }
 
diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-memfun4.C b/gcc/testsuite/g++.dg/cpp2a/concepts-memfun4.C
index cf7f13c007d..d849e9129a3 100644
--- a/gcc/testsuite/g++.dg/cpp2a/concepts-memfun4.C
+++ b/gcc/testsuite/g++.dg/cpp2a/concepts-memfun4.C
@@ -91,7 +91,7 @@  namespace N1 {
 
   A<> a;
   B<> b;
-  // when comparing the A op== to the reversed B op==, we compare them in
-  // reverse order, so they match, and we choose the more constrained.
-  static_assert (a == b);
+  // A op== and B op== are defined in different classes so constraints
+  // aren't considered, and the tie is broken via reversedness.
+  static_assert (!(a == b));
 }