self-comparison.c revision b82dcd827495592a8748692ce4bf80402f21b8d4
1// RUN: clang -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