Bug 117788 - [C++26] P2865R5 - Removing deprecated array comparisons
Summary: [C++26] P2865R5 - Removing deprecated array comparisons
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 15.0
: P3 normal
Target Milestone: ---
Assignee: Marek Polacek
URL:
Keywords:
Depends on:
Blocks: c++26-core
  Show dependency treegraph
 
Reported: 2024-11-26 09:34 UTC by Jakub Jelinek
Modified: 2024-12-10 15:21 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2024-11-26 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jakub Jelinek 2024-11-26 09:34:28 UTC
See <https://wg21.link/P2865R5>.
Comment 1 Marek Polacek 2024-11-26 15:08:24 UTC
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.
Comment 2 Jakub Jelinek 2024-11-26 15:22:07 UTC
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.
Comment 3 Marek Polacek 2024-11-27 14:25:00 UTC
Perhaps we can promote the warning to an error in C++26, and leave the rest of the changes for GCC 16.
Comment 4 Jakub Jelinek 2024-11-27 15:14:32 UTC
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
Comment 5 GCC Commits 2024-12-10 15:17:32 UTC
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>
Comment 6 Marek Polacek 2024-12-10 15:21:21 UTC
Done in GCC 15.