Repository navigation
diagnose comparisons between two arrays (P2865), fix for [GH #370] #387
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mohitmishra786
wants to merge
6
commits into
edgcpp:main
Choose a base branch
from
mohitmishra786:gh-370-array-comparisons
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,020
−2
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
aff7624
Diagnose a comparison between two arrays: deprecated in C++20, not al…
mohitmishra786 3da31c6
Update recordings for the new array comparison diagnostics. [GH #370]
mohitmishra786 b62870b
Also diagnose array comparisons through conversion functions. [GH #370]
mohitmishra786 197630c
Diagnose array comparisons with implicit qualification conversions, a…
mohitmishra786 8cf11d6
Update Clang test recordings for the array comparison warning before …
mohitmishra786 abd74f2
Update edg_x86_32_cp recordings of SemaCXX/deprecated for the array c…
mohitmishra786 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| [GH #370] | ||
| C++26: comparison between two arrays is not allowed | ||
|
|
||
| A comparison between two arrays using an equality or relational operator is | ||
| deprecated in C++20 and not allowed in C++26 (P2865). The front end did not | ||
| diagnose it. It is now a warning in C++20 and C++23, and an error in C++26 | ||
| (only a warning when emulating GCC versions before 15 or Clang versions before | ||
| 20, which do the same). Before C++20 it is a remark (a warning when | ||
| emulating Clang 20 or later, which warns by default). This includes class | ||
| operands that are converted to arrays by a conversion function. For | ||
| example, with --c++26: | ||
|
|
||
| int a[2], b[2]; | ||
| bool x = a == b; // Now an error. | ||
| bool y = a == &b[0]; // Okay: one operand is a pointer. | ||
| struct C { using A = int[2]; operator A &() const; } c; | ||
| bool z = c == c; // Now an error. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| fe_only -DTEST_NUMBER=1 --c++26 Test_name.c | ||
| "Test_name.c", line 10: error: comparison between two arrays is not allowed | ||
| bool x1 = a == b; // Two arrays: diagnosed. | ||
| ^ | ||
|
|
||
| "Test_name.c", line 11: error: comparison between two arrays is not allowed | ||
| bool x2 = a != b; | ||
| ^ | ||
|
|
||
| "Test_name.c", line 12: error: comparison between two arrays is not allowed | ||
| bool x3 = a < b; | ||
| ^ | ||
|
|
||
| "Test_name.c", line 13: error: comparison between two arrays is not allowed | ||
| bool x4 = a >= b; | ||
| ^ | ||
|
|
||
| "Test_name.c", line 22: error: comparison between two arrays is not allowed | ||
| bool z1 = c == c; // Two arrays: diagnosed. | ||
| ^ | ||
|
|
||
| "Test_name.c", line 23: error: comparison between two arrays is not allowed | ||
| bool z2 = c < c; | ||
| ^ | ||
|
|
||
| "Test_name.c", line 24: error: comparison between two arrays is not allowed | ||
| bool z3 = c == a; | ||
| ^ | ||
|
|
||
| "Test_name.c", line 33: error: comparison between two arrays is not allowed | ||
| bool h1(C c) { return c == ca; } // Two arrays: diagnosed. | ||
| ^ | ||
|
|
||
| 8 errors detected in the compilation of "Test_name.c". |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| fe_only -DTEST_NUMBER=2 --c++26 --gnu_version 150000 Test_name.c | ||
| "Test_name.c", line 10: error: comparison between two arrays is not allowed | ||
| bool x1 = a == b; // Two arrays: diagnosed. | ||
| ^ | ||
|
|
||
| "Test_name.c", line 11: error: comparison between two arrays is not allowed | ||
| bool x2 = a != b; | ||
| ^ | ||
|
|
||
| "Test_name.c", line 12: error: comparison between two arrays is not allowed | ||
| bool x3 = a < b; | ||
| ^ | ||
|
|
||
| "Test_name.c", line 13: error: comparison between two arrays is not allowed | ||
| bool x4 = a >= b; | ||
| ^ | ||
|
|
||
| "Test_name.c", line 22: error: comparison between two arrays is not allowed | ||
| bool z1 = c == c; // Two arrays: diagnosed. | ||
| ^ | ||
|
|
||
| "Test_name.c", line 23: error: comparison between two arrays is not allowed | ||
| bool z2 = c < c; | ||
| ^ | ||
|
|
||
| "Test_name.c", line 24: error: comparison between two arrays is not allowed | ||
| bool z3 = c == a; | ||
| ^ | ||
|
|
||
| "Test_name.c", line 33: error: comparison between two arrays is not allowed | ||
| bool h1(C c) { return c == ca; } // Two arrays: diagnosed. | ||
| ^ | ||
|
|
||
| 8 errors detected in the compilation of "Test_name.c". |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| fe_only -DTEST_NUMBER=3 --c++26 --clang_version 200000 Test_name.c | ||
| "Test_name.c", line 10: error: comparison between two arrays is not allowed | ||
| bool x1 = a == b; // Two arrays: diagnosed. | ||
| ^ | ||
|
|
||
| "Test_name.c", line 11: error: comparison between two arrays is not allowed | ||
| bool x2 = a != b; | ||
| ^ | ||
|
|
||
| "Test_name.c", line 12: error: comparison between two arrays is not allowed | ||
| bool x3 = a < b; | ||
| ^ | ||
|
|
||
| "Test_name.c", line 13: error: comparison between two arrays is not allowed | ||
| bool x4 = a >= b; | ||
| ^ | ||
|
|
||
| "Test_name.c", line 22: error: comparison between two arrays is not allowed | ||
| bool z1 = c == c; // Two arrays: diagnosed. | ||
| ^ | ||
|
|
||
| "Test_name.c", line 23: error: comparison between two arrays is not allowed | ||
| bool z2 = c < c; | ||
| ^ | ||
|
|
||
| "Test_name.c", line 24: error: comparison between two arrays is not allowed | ||
| bool z3 = c == a; | ||
| ^ | ||
|
|
||
| "Test_name.c", line 33: error: comparison between two arrays is not allowed | ||
| bool h1(C c) { return c == ca; } // Two arrays: diagnosed. | ||
| ^ | ||
|
|
||
| 8 errors detected in the compilation of "Test_name.c". |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| fe_only -DTEST_NUMBER=1 --c++20 Test_name.c | ||
| "Test_name.c", line 13: warning: comparison between two arrays is deprecated | ||
| bool x1 = a == b; // Two arrays: diagnosed. | ||
| ^ | ||
|
|
||
| "Test_name.c", line 14: warning: comparison between two arrays is deprecated | ||
| bool x2 = a != b; | ||
| ^ | ||
|
|
||
| "Test_name.c", line 15: warning: comparison between two arrays is deprecated | ||
| bool x3 = a < b; | ||
| ^ | ||
|
|
||
| "Test_name.c", line 16: warning: comparison between two arrays is deprecated | ||
| bool x4 = a >= b; | ||
| ^ | ||
|
|
||
| "Test_name.c", line 25: warning: comparison between two arrays is deprecated | ||
| bool z1 = c == c; // Two arrays: diagnosed. | ||
| ^ | ||
|
|
||
| "Test_name.c", line 26: warning: comparison between two arrays is deprecated | ||
| bool z2 = c < c; | ||
| ^ | ||
|
|
||
| "Test_name.c", line 27: warning: comparison between two arrays is deprecated | ||
| bool z3 = c == a; | ||
| ^ | ||
|
|
||
| "Test_name.c", line 36: warning: comparison between two arrays is deprecated | ||
| bool h1(C c) { return c == ca; } // Two arrays: diagnosed. | ||
| ^ | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| fe_only -DTEST_NUMBER=2 --c++26 --gnu_version 140000 Test_name.c | ||
| "Test_name.c", line 13: warning: comparison between two arrays is deprecated | ||
| bool x1 = a == b; // Two arrays: diagnosed. | ||
| ^ | ||
|
|
||
| "Test_name.c", line 14: warning: comparison between two arrays is deprecated | ||
| bool x2 = a != b; | ||
| ^ | ||
|
|
||
| "Test_name.c", line 15: warning: comparison between two arrays is deprecated | ||
| bool x3 = a < b; | ||
| ^ | ||
|
|
||
| "Test_name.c", line 16: warning: comparison between two arrays is deprecated | ||
| bool x4 = a >= b; | ||
| ^ | ||
|
|
||
| "Test_name.c", line 25: warning: comparison between two arrays is deprecated | ||
| bool z1 = c == c; // Two arrays: diagnosed. | ||
| ^ | ||
|
|
||
| "Test_name.c", line 26: warning: comparison between two arrays is deprecated | ||
| bool z2 = c < c; | ||
| ^ | ||
|
|
||
| "Test_name.c", line 27: warning: comparison between two arrays is deprecated | ||
| bool z3 = c == a; | ||
| ^ | ||
|
|
||
| "Test_name.c", line 36: warning: comparison between two arrays is deprecated | ||
| bool h1(C c) { return c == ca; } // Two arrays: diagnosed. | ||
| ^ | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| fe_only -DTEST_NUMBER=3 --c++26 --clang_version 190000 Test_name.c | ||
| "Test_name.c", line 13: warning: comparison between two arrays is deprecated | ||
| bool x1 = a == b; // Two arrays: diagnosed. | ||
| ^ | ||
|
|
||
| "Test_name.c", line 14: warning: comparison between two arrays is deprecated | ||
| bool x2 = a != b; | ||
| ^ | ||
|
|
||
| "Test_name.c", line 15: warning: comparison between two arrays is deprecated | ||
| bool x3 = a < b; | ||
| ^ | ||
|
|
||
| "Test_name.c", line 16: warning: comparison between two arrays is deprecated | ||
| bool x4 = a >= b; | ||
| ^ | ||
|
|
||
| "Test_name.c", line 25: warning: comparison between two arrays is deprecated | ||
| bool z1 = c == c; // Two arrays: diagnosed. | ||
| ^ | ||
|
|
||
| "Test_name.c", line 26: warning: comparison between two arrays is deprecated | ||
| bool z2 = c < c; | ||
| ^ | ||
|
|
||
| "Test_name.c", line 27: warning: comparison between two arrays is deprecated | ||
| bool z3 = c == a; | ||
| ^ | ||
|
|
||
| "Test_name.c", line 36: warning: comparison between two arrays is deprecated | ||
| bool h1(C c) { return c == ca; } // Two arrays: diagnosed. | ||
| ^ | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| fe_only -DTEST_NUMBER=4 --c++17 Test_name.c |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| fe_only -DTEST_NUMBER=5 --c++17 --remarks Test_name.c | ||
| "Test_name.c", line 13: remark: comparison between two arrays compares their addresses | ||
| bool x1 = a == b; // Two arrays: diagnosed. | ||
| ^ | ||
|
|
||
| "Test_name.c", line 14: remark: comparison between two arrays compares their addresses | ||
| bool x2 = a != b; | ||
| ^ | ||
|
|
||
| "Test_name.c", line 15: remark: comparison between two arrays compares their addresses | ||
| bool x3 = a < b; | ||
| ^ | ||
|
|
||
| "Test_name.c", line 16: remark: comparison between two arrays compares their addresses | ||
| bool x4 = a >= b; | ||
| ^ | ||
|
|
||
| "Test_name.c", line 25: remark: comparison between two arrays compares their addresses | ||
| bool z1 = c == c; // Two arrays: diagnosed. | ||
| ^ | ||
|
|
||
| "Test_name.c", line 26: remark: comparison between two arrays compares their addresses | ||
| bool z2 = c < c; | ||
| ^ | ||
|
|
||
| "Test_name.c", line 27: remark: comparison between two arrays compares their addresses | ||
| bool z3 = c == a; | ||
| ^ | ||
|
|
||
| "Test_name.c", line 25: remark: variable "z1" was declared but never referenced | ||
| bool z1 = c == c; // Two arrays: diagnosed. | ||
| ^ | ||
|
|
||
| "Test_name.c", line 26: remark: variable "z2" was declared but never referenced | ||
| bool z2 = c < c; | ||
| ^ | ||
|
|
||
| "Test_name.c", line 27: remark: variable "z3" was declared but never referenced | ||
| bool z3 = c == a; | ||
| ^ | ||
|
|
||
| "Test_name.c", line 28: remark: variable "z4" was declared but never referenced | ||
| bool z4 = c == p; // Array and pointer: not diagnosed. | ||
| ^ | ||
|
|
||
| "Test_name.c", line 29: remark: variable "z5" was declared but never referenced | ||
| bool z5 = q == q; // Conversions to pointers: not diagnosed. | ||
| ^ | ||
|
|
||
| "Test_name.c", line 30: remark: variable "z6" was declared but never referenced | ||
| bool z6 = +c == +c; // Explicit decay: not diagnosed. | ||
| ^ | ||
|
|
||
| "Test_name.c", line 36: remark: comparison between two arrays compares their addresses | ||
| bool h1(C c) { return c == ca; } // Two arrays: diagnosed. | ||
| ^ | ||
|
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.)