self-comparison.c revision d1e4d9bfd57f643d950eb1373f582bda4dfb8dc7
1// RUN: %clang_cc1 -fsyntax-only -verify %s
2
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
11int 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
19int bar(float x) {
20  return x == x; // no-warning
21}
22
23int bar2(float x) {
24  return x != x; // no-warning
25}
26
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}
34
35// Don't complain in unevaluated contexts.
36int compare_sizeof(int x) {
37  return sizeof(x == x); // no-warning
38}
39