1 // RUN: %clang %s -fsyntax-only -Wignored-qualifiers -Wreturn-type -Xclang -verify -fblocks -Wno-unreachable-code -Wno-unused-value
3 // clang emits the following warning by default.
4 // With GCC, -pedantic, -Wreturn-type or -Wall are required to produce the
7 return; // expected-warning {{non-void function 't14' should return a value}}
11 return 1; // expected-warning {{void function 't15' should not return a value}}
20 } // expected-warning {{control reaches end of non-void function}}
29 } // expected-warning {{control reaches end of non-void function}}
36 void halt2() __attribute__((noreturn
));
51 int unknown_nohalt() {
57 } // expected-warning {{control reaches end of non-void function}}
60 (void)(1 + unknown());
61 } // expected-warning {{control reaches end of non-void function}}
63 int halt3() __attribute__((noreturn
));
66 (void)(halt3() + unknown());
70 (void)(unknown() || halt3());
71 } // expected-warning {{control may reach end of non-void function}}
74 (void)(unknown() && halt3());
75 } // expected-warning {{control may reach end of non-void function}}
78 (void)(halt3() || unknown());
82 (void)(halt3() && unknown());
86 (void)(1 || unknown());
87 } // expected-warning {{control reaches end of non-void function}}
90 (void)(0 || unknown());
91 } // expected-warning {{control reaches end of non-void function}}
94 (void)(0 && unknown());
95 } // expected-warning {{control reaches end of non-void function}}
98 (void)(1 && unknown());
99 } // expected-warning {{control reaches end of non-void function}}
102 (void)(unknown_nohalt() && halt3());
103 } // expected-warning {{control may reach end of non-void function}}
106 (void)(unknown_nohalt() && unknown());
107 } // expected-warning {{control reaches end of non-void function}}
115 } // expected-warning {{control may reach end of non-void function}}
127 switch (i
) default: ;
128 } // expected-warning {{control reaches end of non-void function}}
138 } // expected-warning {{control may reach end of non-void function}}
153 1 ? halt3() : unknown();
157 0 ? halt3() : unknown();
158 } // expected-warning {{control reaches end of non-void function}}
161 void (*fptr
)() __attribute__((noreturn
));
177 while (0) { goto done
; }
180 while (1) { return 1; }
192 void test28() __attribute__((noreturn
));
193 void test28(x
) { while (1) { } }
204 longjmp(test30_j
, 1);
206 #if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__)
207 longjmp(test30_j
, 2);
209 _longjmp(test30_j
, 1);
213 typedef void test31_t(int status
);
214 void test31(test31_t
*callback
__attribute__((noreturn
)));
217 ^ (void) { while (1) { } }();
218 ^ (void) { if (j
) while (1) { } }();
226 // Test that 'static inline' functions are only analyzed for CFG-based warnings
227 // when they are used.
228 static inline int si_has_missing_return() {} // expected-warning{{control reaches end of non-void function}}
229 static inline int si_has_missing_return_2() {}; // expected-warning{{control reaches end of non-void function}}
230 static inline int si_forward();
231 static inline int si_has_missing_return_3(int x
) {
233 return si_has_missing_return_3(x
+1);
234 } // expected-warning{{control may reach end of non-void function}}
236 int test_static_inline(int x
) {
238 return x
? si_has_missing_return_2() : si_has_missing_return_3(x
);
240 static inline int si_forward() {} // expected-warning{{control reaches end of non-void function}}
242 // Test warnings on ignored qualifiers on return types.
243 const int ignored_c_quals(); // expected-warning{{'const' type qualifier on return type has no effect}}
244 const volatile int ignored_cv_quals(); // expected-warning{{'const volatile' type qualifiers on return type have no effect}}
246 // Test that for switch(enum) that if the switch statement covers all the cases
247 // that we don't consider that for -Wreturn-type.
248 enum Cases
{ C1
, C2
, C3
, C4
};
249 int test_enum_cases(enum Cases C
) {