You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Clang] Add '-Warray-compare' flag for C++ below version 20 (#118031)
Currently, we support `-wdeprecated-array-compare` for C++20 or above
and don't report any warning for older versions, this PR supports
`-Warray-compare` for older versions and for GCC compatibility.
Fixes#114770
Copy file name to clipboardExpand all lines: clang/test/Sema/warn-stringcompare.c
+5-5Lines changed: 5 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
// RUN: %clang_cc1 -x c -fsyntax-only -verify %s
2
-
// RUN: %clang_cc1 -x c++ -fsyntax-only -verify %s
2
+
// RUN: %clang_cc1 -x c++ -fsyntax-only -verify=expected,cxx %s
3
3
4
4
#defineDELIM "/"
5
5
#defineDOT "."
@@ -15,15 +15,15 @@ void test(const char *d) {
15
15
if (NULL=="/")
16
16
return;
17
17
if ("/"!=DELIM) // expected-warning {{result of comparison against a string literal is unspecified (use an explicit string comparison function instead)}}
18
-
return;
18
+
return;// cxx-warning@-1 {{comparison between two arrays}}
19
19
if (DELIM=="/") // expected-warning {{result of comparison against a string literal is unspecified (use an explicit string comparison function instead)}}
20
-
return;
20
+
return;// cxx-warning@-1 {{comparison between two arrays}}
21
21
if (DELIM!=NULL)
22
22
return;
23
23
if (NULL==DELIM)
24
24
return;
25
25
if (DOT!=DELIM) // expected-warning {{result of comparison against a string literal is unspecified (use an explicit string comparison function instead)}}
26
-
return;
26
+
return;// cxx-warning@-1 {{comparison between two arrays}}
27
27
if (DELIM==DOT) // expected-warning {{result of comparison against a string literal is unspecified (use an explicit string comparison function instead)}}
28
-
return;
28
+
return;// cxx-warning@-1 {{comparison between two arrays}}
Copy file name to clipboardExpand all lines: clang/test/SemaCXX/deprecated.cpp
+7-5Lines changed: 7 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -246,17 +246,19 @@ namespace ArithConv {
246
246
247
247
namespaceArrayComp {
248
248
int arr1[3], arr2[4];
249
-
bool b1 = arr1 == arr2; // expected-warning {{array comparison always evaluates to false}} cxx20-warning {{comparison between two arrays is deprecated}}
250
-
bool b2 = arr1 < arr2; // expected-warning {{array comparison always evaluates to a constant}} cxx20-warning {{comparison between two arrays is deprecated}}
249
+
bool b1 = arr1 == arr2; // not-cxx20-warning {{comparison between two arrays compare their addresses}} cxx20-warning {{comparison between two arrays is deprecated}}
250
+
// expected-warning@-1 {{array comparison always evaluates to false}}
251
+
bool b2 = arr1 < arr2; // not-cxx20-warning {{comparison between two arrays compare their addresses}} cxx20-warning {{comparison between two arrays is deprecated}}
252
+
// expected-warning@-1 {{array comparison always evaluates to a constant}}
251
253
__attribute__((weak)) int arr3[3];
252
-
bool b3 = arr1 == arr3; // cxx20-warning {{comparison between two arrays is deprecated}}
253
-
bool b4 = arr1 < arr3; // cxx20-warning {{comparison between two arrays is deprecated}}
254
+
bool b3 = arr1 == arr3; //not-cxx20-warning {{comparison between two arrays compare their addresses}} cxx20-warning {{comparison between two arrays is deprecated}}
255
+
bool b4 = arr1 < arr3; //not-cxx20-warning {{comparison between two arrays compare their addresses}} cxx20-warning {{comparison between two arrays is deprecated}}
bool b6 = arr1 == f(); // cxx20-warning {{comparison between two arrays is deprecated}}
261
+
bool b6 = arr1 == f(); //not-cxx20-warning {{comparison between two arrays compare their addresses}} cxx20-warning {{comparison between two arrays is deprecated}}
if (obj1.str != obj2.str) // not-cxx20-warning {{comparison between two arrays compare their addresses}} cxx20-warning {{comparison between two arrays is deprecated}}
12
+
returnfalse;
13
+
if (obj1.id != obj2.id) // not-cxx20-warning {{comparison between two arrays compare their addresses}} cxx20-warning {{comparison between two arrays is deprecated}}
14
+
returnfalse;
15
+
returntrue;
16
+
}
17
+
18
+
19
+
voidfoo(int (&array1)[2], int (&array2)[2]) {
20
+
if (array1 == array2) { } // not-cxx20-warning {{comparison between two arrays compare their addresses}} cxx20-warning {{comparison between two arrays is deprecated}}
if (array1 == array2) { } //not-cxx20-warning {{comparison between two arrays compare their addresses}} cxx20-warning {{comparison between two arrays is deprecated}}
0 commit comments