-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[Clang] Add '-Warray-compare' flag for C++ below version 20 #118031
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
Changes from 8 commits
9451a1e
6de4cba
fe4fab8
bece937
ef7485c
b2034a4
49730e1
80ecba0
b98e0f8
55e3489
cc67aa8
d3ff02d
3636a8f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10264,6 +10264,10 @@ def warn_depr_array_comparison : Warning< | |
| "to compare array addresses, use unary '+' to decay operands to pointers">, | ||
| InGroup<DeprecatedArrayCompare>; | ||
|
|
||
| def warn_array_comparison : Warning< | ||
| "comparison between two arrays compare their addresses and will be deprecated in c++20; " | ||
| "to compare array addresses, use unary '+' to decay operands to pointers">; | ||
|
||
|
|
||
| def warn_stringcompare : Warning< | ||
| "result of comparison against %select{a string literal|@encode}0 is " | ||
| "unspecified (use an explicit string comparison function instead)">, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| // RUN: %clang_cc1 -x c -fsyntax-only -verify %s | ||
| // RUN: %clang_cc1 -x c++ -fsyntax-only -verify %s | ||
| // RUN: %clang_cc1 -x c++ -fsyntax-only -verify=expected,cxx %s | ||
|
|
||
| #define DELIM "/" | ||
| #define DOT "." | ||
|
|
@@ -15,15 +15,15 @@ void test(const char *d) { | |
| if (NULL == "/") | ||
| return; | ||
| if ("/" != DELIM) // expected-warning {{result of comparison against a string literal is unspecified (use an explicit string comparison function instead)}} | ||
| return; | ||
| return; // cxx-warning@-1 {{comparison between two arrays}} | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems to overlap w/ We can do this as part of the C++26 feature implementation.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CC @erichkeane
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oooh, thats a great concern! I think you're right, but I think as well that it is ok to do in the followup |
||
| if (DELIM == "/") // expected-warning {{result of comparison against a string literal is unspecified (use an explicit string comparison function instead)}} | ||
| return; | ||
| return; // cxx-warning@-1 {{comparison between two arrays}} | ||
| if (DELIM != NULL) | ||
| return; | ||
| if (NULL == DELIM) | ||
| return; | ||
| if (DOT != DELIM) // expected-warning {{result of comparison against a string literal is unspecified (use an explicit string comparison function instead)}} | ||
| return; | ||
| return; // cxx-warning@-1 {{comparison between two arrays}} | ||
| if (DELIM == DOT) // expected-warning {{result of comparison against a string literal is unspecified (use an explicit string comparison function instead)}} | ||
| return; | ||
| return; // cxx-warning@-1 {{comparison between two arrays}} | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| // RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify %s -verify=expected,not-cxx20 | ||
| // RUN: %clang_cc1 -std=c++20 -fsyntax-only -Wno-deprecated-array-compare -verify %s -verify=expected,not-cxx20 | ||
| // RUN: %clang_cc1 -std=c++20 -fsyntax-only -Wdeprecated -verify %s -verify=expected,cxx20 | ||
|
|
||
| typedef struct { | ||
| char str[16]; | ||
| int id[16]; | ||
| } Object; | ||
|
|
||
| bool object_equal(const Object &obj1, const Object &obj2) { | ||
| if (obj1.str != obj2.str) // not-cxx20-warning {{comparison between two arrays compare their addresses}} cxx20-warning {{comparison between two arrays is deprecated}} | ||
| return false; | ||
| if (obj1.id != obj2.id) // not-cxx20-warning {{comparison between two arrays compare their addresses}} cxx20-warning {{comparison between two arrays is deprecated}} | ||
| return false; | ||
| return true; | ||
| } | ||
|
|
||
|
|
||
| void foo(int (&array1)[2], int (&array2)[2]) { | ||
| if (array1 == array2) { } // not-cxx20-warning {{comparison between two arrays compare their addresses}} cxx20-warning {{comparison between two arrays is deprecated}} | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| // RUN: %clang_cc1 -fsyntax-only -verify %s | ||
| // expected-no-diagnostics | ||
| // RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify %s -verify=expected,not-cxx20 | ||
| // RUN: %clang_cc1 -std=c++20 -fsyntax-only -Wdeprecated -verify %s -verify=expected,cxx20 | ||
|
|
||
| void f(int (&array1)[2], int (&array2)[2]) { | ||
| if (array1 == array2) { } // no warning | ||
| if (array1 == array2) { } // not-cxx20-warning {{comparison between two arrays compare their addresses}} cxx20-warning {{comparison between two arrays is deprecated}} | ||
| } |
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.
Remove this please
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.
Done, thanks