Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
Ted Kremenek | 3ca0bf2 | 2007-10-29 16:58:49 +0000 | [diff] [blame] | 2 | |
| 3 | int foo(int x) { |
| 4 | return x == x; // expected-warning {{self-comparison always results}} |
| 5 | } |
| 6 | |
| 7 | int foo2(int x) { |
| 8 | return (x) != (((x))); // expected-warning {{self-comparison always results}} |
| 9 | } |
| 10 | |
Ted Kremenek | a8335a9 | 2007-10-29 17:02:56 +0000 | [diff] [blame] | 11 | int qux(int x) { |
| 12 | return x < x; // expected-warning {{self-comparison}} |
| 13 | } |
| 14 | |
| 15 | int qux2(int x) { |
| 16 | return x > x; // expected-warning {{self-comparison}} |
| 17 | } |
| 18 | |
Ted Kremenek | 3ca0bf2 | 2007-10-29 16:58:49 +0000 | [diff] [blame] | 19 | int bar(float x) { |
| 20 | return x == x; // no-warning |
| 21 | } |
| 22 | |
| 23 | int bar2(float x) { |
| 24 | return x != x; // no-warning |
Ted Kremenek | a8335a9 | 2007-10-29 17:02:56 +0000 | [diff] [blame] | 25 | } |
Ted Kremenek | b82dcd8 | 2009-03-20 18:35:45 +0000 | [diff] [blame] | 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. |
| 30 | int compare_enum() { |
| 31 | enum { A }; |
| 32 | return A == A; // no-warning |
| 33 | } |
Douglas Gregor | d1e4d9b | 2010-01-12 23:18:54 +0000 | [diff] [blame] | 34 | |
| 35 | // Don't complain in unevaluated contexts. |
| 36 | int compare_sizeof(int x) { |
| 37 | return sizeof(x == x); // no-warning |
| 38 | } |