1 // RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -verify -Wno-unused -Wunused-comparison %s
4 bool operator==(const A
&);
5 bool operator!=(const A
&);
6 bool operator<(const A
&);
7 bool operator>(const A
&);
8 bool operator<=(const A
&);
9 bool operator>=(const A
&);
10 A
operator|=(const A
&);
18 x
== 7; // expected-warning {{equality comparison result unused}} \
19 // expected-note {{use '=' to turn this equality comparison into an assignment}}
20 x
!= 7; // expected-warning {{inequality comparison result unused}} \
21 // expected-note {{use '|=' to turn this inequality comparison into an or-assignment}}
22 x
< 7; // expected-warning {{relational comparison result unused}}
23 x
> 7; // expected-warning {{relational comparison result unused}}
24 x
<= 7; // expected-warning {{relational comparison result unused}}
25 x
>= 7; // expected-warning {{relational comparison result unused}}
27 7 == x
; // expected-warning {{equality comparison result unused}}
28 p
== p
; // expected-warning {{equality comparison result unused}} \
29 // expected-note {{use '=' to turn this equality comparison into an assignment}} \
30 // expected-warning {{self-comparison always evaluates to true}}
31 a
== a
; // expected-warning {{equality comparison result unused}} \
32 // expected-note {{use '=' to turn this equality comparison into an assignment}}
33 a
== b
; // expected-warning {{equality comparison result unused}} \
34 // expected-note {{use '=' to turn this equality comparison into an assignment}}
35 a
!= b
; // expected-warning {{inequality comparison result unused}} \
36 // expected-note {{use '|=' to turn this inequality comparison into an or-assignment}}
37 a
< b
; // expected-warning {{relational comparison result unused}}
38 a
> b
; // expected-warning {{relational comparison result unused}}
39 a
<= b
; // expected-warning {{relational comparison result unused}}
40 a
>= b
; // expected-warning {{relational comparison result unused}}
42 A() == b
; // expected-warning {{equality comparison result unused}}
43 if (42) x
== 7; // expected-warning {{equality comparison result unused}} \
44 // expected-note {{use '=' to turn this equality comparison into an assignment}}
45 else if (42) x
== 7; // expected-warning {{equality comparison result unused}} \
46 // expected-note {{use '=' to turn this equality comparison into an assignment}}
47 else x
== 7; // expected-warning {{equality comparison result unused}} \
48 // expected-note {{use '=' to turn this equality comparison into an assignment}}
49 do x
== 7; // expected-warning {{equality comparison result unused}} \
50 // expected-note {{use '=' to turn this equality comparison into an assignment}}
52 while (false) x
== 7; // expected-warning {{equality comparison result unused}} \
53 // expected-note {{use '=' to turn this equality comparison into an assignment}}
54 for (x
== 7; // expected-warning {{equality comparison result unused}} \
55 // expected-note {{use '=' to turn this equality comparison into an assignment}}
56 x
== 7; // No warning -- result is used
57 x
== 7) // expected-warning {{equality comparison result unused}} \
58 // expected-note {{use '=' to turn this equality comparison into an assignment}}
59 x
== 7; // expected-warning {{equality comparison result unused}} \
60 // expected-note {{use '=' to turn this equality comparison into an assignment}}
61 switch (42) default: x
== 7; // expected-warning {{equality comparison result unused}} \
62 // expected-note {{use '=' to turn this equality comparison into an assignment}}
63 switch (42) case 42: x
== 7; // expected-warning {{equality comparison result unused}} \
64 // expected-note {{use '=' to turn this equality comparison into an assignment}}
71 x
== 7; // expected-warning {{equality comparison result unused}} \
72 // expected-note {{use '=' to turn this equality comparison into an assignment}}
76 (void)(p
== p
); // expected-warning {{self-comparison always evaluates to true}}
79 { bool b
= ({ x
== 7; // expected-warning {{equality comparison result unused}} \
80 // expected-note {{use '=' to turn this equality comparison into an assignment}}
81 x
== 7; }); } // no warning on the second, its result is used!
83 #define EQ(x,y) (x) == (y)
87 (void)sizeof(1 < 2, true); // No warning; unevaluated context.
116 stream
&operator<(stream
&s
, int);
117 bool operator<(stream
&s
, stream
&s2
);
120 cout
< 5; // no warning, operator returns a reference
121 cout
< cin
; // expected-warning {{relational comparison result unused}}
127 void operator!=(int);
134 s
== 1; // expected-warning{{equality comparison result unused}}
135 // expected-note@-1{{use '=' to turn this equality comparison into an assignment}}