blob: fd50d0792afc41b63b358bdcaae1545bde58b591 [file] [log] [blame]
Steve Naroff2c0ccd02009-04-30 16:01:26 +00001// RUN: clang-cc %s -fsyntax-only -verify
2
3// clang emits the following warning by default.
4// With GCC, -pedantic, -Wreturn-type or -Wall are required to produce the
5// following warning.
6int t14() {
7 return; // expected-warning {{non-void function 't14' should return a value}}
8}
9
Steve Naroff940ab972009-04-30 17:53:16 +000010void t15() {
11 return 1; // expected-warning {{void function 't15' should not return a value}}
12}
Mike Stumpb1682c52009-07-22 23:56:57 +000013
14int unknown();
15
16void test0() {
17}
18
19int test1() {
20} // expected-warning {{control reaches end of non-void function}}
21
22int test2() {
23 a: goto a;
24}
25
26int test3() {
27 goto a;
28 a: ;
29} // expected-warning {{control reaches end of non-void function}}
30
31
32void halt() {
33 a: goto a;
34}
35
36void halt2() __attribute__((noreturn));
37
38int test4() {
39 halt2();
40}
41
42int test5() {
43 halt2(), (void)1;
44}
45
46int test6() {
47 1, halt2();
48}
49
50int j;
51int unknown_nohalt() {
52 return j;
53}
54
55int test7() {
56 unknown();
57} // expected-warning {{control reaches end of non-void function}}
58
59int test8() {
60 (void)(1 + unknown());
61} // expected-warning {{control reaches end of non-void function}}
62
63int halt3() __attribute__((noreturn));
64
65int test9() {
66 (void)(halt3() + unknown());
67}
68
69int test10() {
70 (void)(unknown() || halt3());
71} // expected-warning {{control may reach end of non-void function}}
72
73int test11() {
74 (void)(unknown() && halt3());
75} // expected-warning {{control may reach end of non-void function}}
76
77int test12() {
78 (void)(halt3() || unknown());
79}
80
81int test13() {
82 (void)(halt3() && unknown());
83}
84
85int test14() {
86 (void)(1 || unknown());
87} // expected-warning {{control reaches end of non-void function}}
88
89int test15() {
90 (void)(0 || unknown());
91} // expected-warning {{control reaches end of non-void function}}
92
93int test16() {
94 (void)(0 && unknown());
95} // expected-warning {{control reaches end of non-void function}}
96
97int test17() {
98 (void)(1 && unknown());
99} // expected-warning {{control reaches end of non-void function}}
100
101int test18() {
102 (void)(unknown_nohalt() && halt3());
103} // expected-warning {{control may reach end of non-void function}}
104
105int test19() {
106 (void)(unknown_nohalt() && unknown());
107} // expected-warning {{control reaches end of non-void function}}
108
109int test20() {
110 int i;
111 if (i)
112 return 0;
113 else if (0)
114 return 2;
115} // expected-warning {{control may reach end of non-void function}}
116
117int test21() {
118 int i;
119 if (i)
120 return 0;
121 else if (1)
122 return 2;
123}
124
125int test22() {
126 int i;
127 switch (i) default: ;
128} // expected-warning {{control reaches end of non-void function}}
129
130int test23() {
131 int i;
132 switch (i) {
133 case 0:
134 return 0;
135 case 2:
136 return 2;
137 }
138} // expected-warning {{control may reach end of non-void function}}
139
140int test24() {
141 int i;
142 switch (i) {
143 case 0:
144 return 0;
145 case 2:
146 return 2;
147 default:
148 return -1;
149 }
150}
151
152int test25() {
153 1 ? halt3() : unknown();
154}
155
156int test26() {
157 0 ? halt3() : unknown();
158} // expected-warning {{control reaches end of non-void function}}
159
160int j;
161int test27() {
162 switch (j) {
163 case 1:
164 do { } while (1);
165 break;
166 case 2:
167 for (;;) ;
168 break;
169 case 3:
170 for (;1;) ;
171 for (;0;) {
172 goto done;
173 }
174 return 1;
175 case 4:
176 while (0) { goto done; }
177 return 1;
178 case 5:
179 while (1) { return 1; }
180 break;
181 default:
182 return 1;
183 }
184 done: ;
185}