blob: 1baba2755f43f902d8cf174208f6f6db17fb5de0 [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
Ted Kremenek3ca0bf22007-10-29 16:58:49 +00002
3int foo(int x) {
4 return x == x; // expected-warning {{self-comparison always results}}
5}
6
7int foo2(int x) {
8 return (x) != (((x))); // expected-warning {{self-comparison always results}}
9}
10
Ted Kremeneka8335a92007-10-29 17:02:56 +000011int qux(int x) {
12 return x < x; // expected-warning {{self-comparison}}
13}
14
15int qux2(int x) {
16 return x > x; // expected-warning {{self-comparison}}
17}
18
Ted Kremenek3ca0bf22007-10-29 16:58:49 +000019int bar(float x) {
20 return x == x; // no-warning
21}
22
23int bar2(float x) {
24 return x != x; // no-warning
Ted Kremeneka8335a92007-10-29 17:02:56 +000025}
Ted Kremenekb82dcd82009-03-20 18:35:45 +000026
27// Motivated by <rdar://problem/6703892>, self-comparisons of enum constants
28// should not be warned about. These can be expanded from macros, and thus
29// are usually deliberate.
30int compare_enum() {
31 enum { A };
32 return A == A; // no-warning
33}
Douglas Gregord1e4d9b2010-01-12 23:18:54 +000034
35// Don't complain in unevaluated contexts.
36int compare_sizeof(int x) {
37 return sizeof(x == x); // no-warning
38}