See <https://wg21.link/P2865R5>.
I added this warning in r12-4148: g.C:3:18: warning: comparison between two arrays is deprecated in C++20 [-Warray-compare] 3 | bool same = arr1 == arr2; // ill-formed; previously well-formed | ~~~~~^~~~~~~ g.C:3:18: note: use unary ‘+’ which decays operands to pointers or ‘&arr1[0] == &arr2[0]’ to compare the addresses so I can make it an error.
Is the paper that simple? I thought it says that the array to pointer conversions no longer happen unless the other operand is a pointer. Doesn't that affect overloaded operators as well? I mean say struct S { bool operator== (int *); }; bool foo () { int a[4] = {}; return S {} == a; } Or are those handled elsewhere? "The converted operands shall have arithmetic, enumeration, or pointer type." and corresponding equality sentences would imply that.
Perhaps we can promote the warning to an error in C++26, and leave the rest of the changes for GCC 16.
It is very much possible it actually is that simple, the overloaded operator behavior is described elsewhere - https://eel.is/c++draft/class.compare so maybe what is written there isn't affected by wording changes in https://eel.is/c++draft/expr.rel and https://eel.is/c++draft/expr.eq
The trunk branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>: https://gcc.gnu.org/g:c628def52c87b40b6270618252488bcd731e1843 commit r15-6083-gc628def52c87b40b6270618252488bcd731e1843 Author: Marek Polacek <polacek@redhat.com> Date: Wed Nov 27 18:00:24 2024 -0500 c++: P2865R5, Remove Deprecated Array Comparisons from C++26 [PR117788] This patch implements P2865R5 by promoting the warning to permerror in C++26 only. In C++20 we should warn even without -Wall. Jason fixed this in r15-5713 but let's add a test that doesn't use -Wall. This caused a FAIL in conditionally_borrowed.cc because we end up comparing two array types in equality_comparable_with -> __weakly_eq_cmp_with. That could be fixed in libstc++, perhaps by adding std::decay in the appropriate place. PR c++/117788 gcc/c-family/ChangeLog: * c-warn.cc (do_warn_array_compare): Emit a permerror in C++26. gcc/cp/ChangeLog: * typeck.cc (cp_build_binary_op) <case EQ_EXPR>: Don't check warn_array_compare. Check tf_warning_or_error instead of just tf_warning. Maybe return an error_mark_node in C++26. <case LE_EXPR>: Likewise. gcc/testsuite/ChangeLog: * c-c++-common/Warray-compare-1.c: Expect an error in C++26. * c-c++-common/Warray-compare-3.c: Likewise. * c-c++-common/Warray-compare-4.c: New test. * c-c++-common/Warray-compare-5.c: New test. * g++.dg/warn/Warray-compare-1.C: New test. libstdc++-v3/ChangeLog: * testsuite/std/ranges/adaptors/conditionally_borrowed.cc: Add a FIXME, adjust. Reviewed-by: Jason Merrill <jason@redhat.com>
Done in GCC 15.