diff options
author | Marek Polacek <polacek@redhat.com> | 2024-11-27 18:00:24 -0500 |
---|---|---|
committer | Marek Polacek <polacek@redhat.com> | 2024-12-10 10:17:07 -0500 |
commit | c628def52c87b40b6270618252488bcd731e1843 (patch) | |
tree | ba9a8b2575cfc30f26ccc830add1bf0ae591d1b9 /gcc/c-family | |
parent | 7a12dc695b1ae70f9fc99baf95b7188af6515ed3 (diff) | |
download | gcc-c628def52c87b40b6270618252488bcd731e1843.zip gcc-c628def52c87b40b6270618252488bcd731e1843.tar.gz gcc-c628def52c87b40b6270618252488bcd731e1843.tar.bz2 |
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>
Diffstat (limited to 'gcc/c-family')
-rw-r--r-- | gcc/c-family/c-warn.cc | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/gcc/c-family/c-warn.cc b/gcc/c-family/c-warn.cc index 140d97a..0b71842 100644 --- a/gcc/c-family/c-warn.cc +++ b/gcc/c-family/c-warn.cc @@ -3820,8 +3820,9 @@ maybe_warn_sizeof_array_div (location_t loc, tree arr, tree arr_type, /* Warn about C++20 [depr.array.comp] array comparisons: "Equality and relational comparisons between two operands of array type are - deprecated." We also warn in C and earlier C++ standards. CODE is - the code for this comparison, OP0 and OP1 are the operands. */ + deprecated." In C++26 this is a permerror. We also warn in C and earlier + C++ standards. CODE is the code for this comparison, OP0 and OP1 are + the operands. */ void do_warn_array_compare (location_t location, tree_code code, tree op0, tree op1) @@ -3834,10 +3835,22 @@ do_warn_array_compare (location_t location, tree_code code, tree op0, tree op1) op1 = TREE_OPERAND (op1, 0); auto_diagnostic_group d; - if (warning_at (location, OPT_Warray_compare, - (c_dialect_cxx () && cxx_dialect >= cxx20) - ? G_("comparison between two arrays is deprecated in C++20") - : G_("comparison between two arrays"))) + diagnostic_t kind = DK_WARNING; + const char *msg; + if (c_dialect_cxx () && cxx_dialect >= cxx20) + { + /* P2865R5 made this comparison ill-formed in C++26. */ + if (cxx_dialect >= cxx26) + { + msg = G_("comparison between two arrays is not allowed in C++26"); + kind = DK_PERMERROR; + } + else + msg = G_("comparison between two arrays is deprecated in C++20"); + } + else + msg = G_("comparison between two arrays"); + if (emit_diagnostic (kind, location, OPT_Warray_compare, msg)) { /* C doesn't allow +arr. */ if (c_dialect_cxx ()) |