Repository navigation
diagnose comparisons between two arrays (P2865), fix for [GH #370] - #387
mohitmishra786 wants to merge 1 commit into
Conversation
|
AcknowlEDG review results updated for
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
AcknowlEDG review results updated for
CI success. |
nv-cmeerw
left a comment
There was a problem hiding this comment.
This should also handle user-defined conversion functions, e.g.
struct C
{
using arr_t = int[2];
operator arr_t &() const;
};
void g(int (&arr)[2], C c)
{
arr == arr;
c == c;
}
0d4eabd to
ee685d1
Compare
|
@nv-cmeerw fixed in ee685d1 (rebased onto main): class operands converted to arrays by a conversion function ( |
|
AcknowlEDG review results updated for
|
|
AcknowlEDG review results updated for
CI success. |
|
Clang diagnosed this with a warning even before C++20 deprecated it. E.g.: https://godbolt.org/z/KvThjdvqv Should we perhaps do something similar with this change? |
daveedvdv-nvidia
left a comment
There was a problem hiding this comment.
Looks good.
I have a question in the conversation about possibly extending the diagnosis to pre-C++20 modes.
|
@daveedvdv-nvidia @nv-cmeerw Thanks, good point. I checked this on Godbolt (x86-64), with no extra warning options:
So my suggestion: before C++20, issue a remark, the way a comma operator in a subscript is handled before C++20, and a warning when emulating Clang 20 or later. It would get its own message, e.g. "comparison between two arrays compares their addresses", since it is not deprecated yet in those modes. C++20 and later stay as in this PR. Does that sound OK, or would you prefer a warning in all modes before C++20? |
|
Yes, the remark idea sounds exactly right — thanks! |
|
There still appears to be an issue with cv-qualifications: |
ee685d1 to
197630c
Compare
|
@nv-cmeerw @daveedvdv-nvidia updated in 197630c:
|
|
AcknowlEDG review results updated for
|
|
AcknowlEDG review results updated for
CI failure. |
|
AcknowlEDG review results updated for
CI success. |
The requested changes have been made.
There was a problem hiding this comment.
This looks great!
But I have some suggested changes nonetheless...
See my comment suggesting making the C++26-mode error discretionary.
Also, I have suggested added tests (attached as diffs for the existing test files).
Ah, and one more thing: Can you rebase and squash into a single commit?
| !clangcpp_version_is(<200000)) { | ||
| /* GCC 15 and Clang 20 implement P2865. Earlier versions only issue a | ||
| deprecation warning. */ | ||
| expr_pos_error(ec_array_comparison_not_allowed, operator_pos); |
There was a problem hiding this comment.
Maybe use expr_pos_diagnostic(es_discretionary_error, ...) here.
That way the error severity can be adjusted by the programmer if needed.
(I think Clang and GCC allow that as well.)
There was a problem hiding this comment.
Done in 7083ca5: the C++26 error now uses expr_pos_diagnostic(es_discretionary_error, ...).
A comparison between two arrays with an equality or relational operator is now a discretionary error in C++26, a deprecation warning in C++20 and C++23, and a remark before C++20 (a warning when emulating Clang 20 or later). When emulating GCC before 15 or Clang before 20, C++26 gets only the warning. Class operands converted to arrays by a conversion function (including through an implicit qualification conversion) are covered too. Co-authored-by: Daveed Vandevoorde <dvandevoorde@nvidia.com>
abd74f2 to
7083ca5
Compare
|
@daveedvdv-nvidia thanks! Rebased onto main and squashed into one commit (7083ca5), with you as co-author for the tests:
Could you please take another look? |
|
AcknowlEDG review results updated for
CI success. |
|
AcknowlEDG review results updated for
|
Fixes #370.
A comparison between two arrays with
==,!=,<,<=,>or>=was accepted silently in every mode. It is deprecated in C++20 and not allowed in C++26 (P2865).process_eq_operatorandprocess_rel_operatornow callcheck_for_array_comparisonbefore the array-to-pointer conversion (the same place<=>already rejects two arrays). If both operands have array type:-std=c++26(checked with the gcc:14 and gcc:15 images); Clang implemented P2865 in Clang 20.A comparison between an array and a pointer is not affected.
Summary by CodeRabbit
Bug Fixes