Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
Anders Carlsson | 2d85f8b | 2007-10-10 20:50:11 +0000 | [diff] [blame] | 2 | |
| 3 | void f1(int a) { |
| 4 | if (a); // expected-warning {{if statement has empty body}} |
| 5 | } |
| 6 | |
| 7 | void f2(int a) { |
| 8 | if (a) {} |
| 9 | } |
Chris Lattner | b96728d | 2007-10-29 05:08:52 +0000 | [diff] [blame] | 10 | |
| 11 | void f3() { |
| 12 | if (1) |
| 13 | xx; // expected-error {{use of undeclared identifier}} |
| 14 | return; // no empty body warning. |
| 15 | } |
| 16 | |
Ted Kremenek | b319817 | 2010-09-16 00:37:05 +0000 | [diff] [blame] | 17 | // Don't warn about an empty body if is expanded from a macro. |
| 18 | void f4(int i) { |
Argyrios Kyrtzidis | a25b6a4 | 2010-11-19 20:54:25 +0000 | [diff] [blame^] | 19 | #define BODY(x) |
Ted Kremenek | b319817 | 2010-09-16 00:37:05 +0000 | [diff] [blame] | 20 | if (i == i) // expected-warning{{self-comparison always evaluates to true}} |
Argyrios Kyrtzidis | a25b6a4 | 2010-11-19 20:54:25 +0000 | [diff] [blame^] | 21 | BODY(0); |
Ted Kremenek | b319817 | 2010-09-16 00:37:05 +0000 | [diff] [blame] | 22 | #undef BODY |
| 23 | } |
| 24 | |
Argyrios Kyrtzidis | a25b6a4 | 2010-11-19 20:54:25 +0000 | [diff] [blame^] | 25 | template <typename T> |
| 26 | void tf() { |
| 27 | #define BODY(x) |
| 28 | if (0) |
| 29 | BODY(0); |
| 30 | #undef BODY |
| 31 | } |
| 32 | |
| 33 | void f5() { |
| 34 | tf<int>(); |
| 35 | } |