blob: ec7f89d68e720b1180e2dcc95c6b5b9cce39997c [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
Anders Carlsson2d85f8b2007-10-10 20:50:11 +00002
3void f1(int a) {
4 if (a); // expected-warning {{if statement has empty body}}
5}
6
7void f2(int a) {
8 if (a) {}
9}
Chris Lattnerb96728d2007-10-29 05:08:52 +000010
11void f3() {
12 if (1)
13 xx; // expected-error {{use of undeclared identifier}}
14 return; // no empty body warning.
15}
16
Ted Kremenekb3198172010-09-16 00:37:05 +000017// Don't warn about an empty body if is expanded from a macro.
18void f4(int i) {
Argyrios Kyrtzidisa25b6a42010-11-19 20:54:25 +000019 #define BODY(x)
Ted Kremenekb3198172010-09-16 00:37:05 +000020 if (i == i) // expected-warning{{self-comparison always evaluates to true}}
Argyrios Kyrtzidisa25b6a42010-11-19 20:54:25 +000021 BODY(0);
Ted Kremenekb3198172010-09-16 00:37:05 +000022 #undef BODY
23}
24
Argyrios Kyrtzidisa25b6a42010-11-19 20:54:25 +000025template <typename T>
26void tf() {
27 #define BODY(x)
28 if (0)
29 BODY(0);
30 #undef BODY
31}
32
33void f5() {
34 tf<int>();
35}