1 // RUN: %clang_cc1 -fsyntax-only -verify %s
4 return x
== x
; // expected-warning {{self-comparison always evaluates to true}}
8 return (x
) != (((x
))); // expected-warning {{self-comparison always evaluates to false}}
11 void foo3(short s
, short t
) {
12 if (s
== s
) {} // expected-warning {{self-comparison always evaluates to true}}
13 if (s
== t
) {} // no-warning
16 void foo4(void* v
, void* w
) {
17 if (v
== v
) {} // expected-warning {{self-comparison always evaluates to true}}
18 if (v
== w
) {} // no-warning
22 return x
< x
; // expected-warning {{self-comparison}}
26 return x
> x
; // expected-warning {{self-comparison}}
30 return x
== x
; // no-warning
34 return x
!= x
; // no-warning
37 #define IS_THE_ANSWER(x) (x == 42)
39 int macro_comparison(void) {
40 return IS_THE_ANSWER(42);
43 // Don't complain in unevaluated contexts.
44 int compare_sizeof(int x
) {
45 return sizeof(x
== x
); // no-warning
48 int array_comparisons(void) {
55 return array1
== array1
; // expected-warning{{self-comparison always evaluates to true}}
56 return array1
!= array1
; // expected-warning{{self-comparison always evaluates to false}}
57 return array1
< array1
; // expected-warning{{self-comparison always evaluates to false}}
58 return array1
<= array1
; // expected-warning{{self-comparison always evaluates to true}}
59 return array1
> array1
; // expected-warning{{self-comparison always evaluates to false}}
60 return array1
>= array1
; // expected-warning{{self-comparison always evaluates to true}}
63 // compare different arrays
65 return array1
== array2
; // expected-warning{{array comparison always evaluates to false}}
66 return array1
!= array2
; // expected-warning{{array comparison always evaluates to true}}
69 // we don't know what these are going to be
71 return array1
< array2
; // expected-warning{{array comparison always evaluates to a constant}}
72 return array1
<= array2
; // expected-warning{{array comparison always evaluates to a constant}}
73 return array1
> array2
; // expected-warning{{array comparison always evaluates to a constant}}
74 return array1
>= array2
; // expected-warning{{array comparison always evaluates to a constant}}
78 // Don't issue a warning when either the left or right side of the comparison
79 // results from a macro expansion.
84 if (R8435950_A
== R8435950_B
) // no-warning
89 __attribute__((weak
)) int weak_1
[3];
90 __attribute__((weak
)) int weak_2
[3];
91 _Bool
compare_weak(void) {
92 return weak_1
== weak_2
;