1 // RUN: %clang_cc1 -triple x86_64-apple-darwin9 %s -fsyntax-only -Wignored-qualifiers -Wno-error=return-type -Wno-error=implicit-int -verify -fblocks -Wno-unreachable-code -Wno-unused-value -Wno-strict-prototypes
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 {{non-void function does not return a value}}
29 } // expected-warning {{non-void function does not return a value}}
36 void halt2(void) __attribute__((noreturn
));
51 int unknown_nohalt(void) {
57 } // expected-warning {{non-void function does not return a value}}
60 (void)(1 + unknown());
61 } // expected-warning {{non-void function does not return a value}}
63 int halt3(void) __attribute__((noreturn
));
66 (void)(halt3() + unknown());
70 (void)(unknown() || halt3());
71 } // expected-warning {{non-void function does not return a value in all control paths}}
74 (void)(unknown() && halt3());
75 } // expected-warning {{non-void function does not return a value in all control paths}}
78 (void)(halt3() || unknown());
82 (void)(halt3() && unknown());
86 (void)(1 || unknown());
87 } // expected-warning {{non-void function does not return a value}}
90 (void)(0 || unknown());
91 } // expected-warning {{non-void function does not return a value}}
94 (void)(0 && unknown());
95 } // expected-warning {{non-void function does not return a value}}
98 (void)(1 && unknown());
99 } // expected-warning {{non-void function does not return a value}}
102 (void)(unknown_nohalt() && halt3());
103 } // expected-warning {{non-void function does not return a value in all control paths}}
106 (void)(unknown_nohalt() && unknown());
107 } // expected-warning {{non-void function does not return a value}}
115 } // expected-warning {{non-void function does not return a value in all control paths}}
127 switch (i
) default: ;
128 } // expected-warning {{non-void function does not return a value}}
138 } // expected-warning {{non-void function does not return a value in all control paths}}
153 1 ? halt3() : unknown();
157 0 ? halt3() : unknown();
158 } // expected-warning {{non-void function does not return a value}}
161 void (*fptr
)(void) __attribute__((noreturn
));
177 while (0) { goto done
; }
180 while (1) { return 1; }
192 void test28() __attribute__((noreturn
));
193 void test28(x
) { while (1) { } } // expected-warning {{parameter 'x' was not declared, defaults to 'int'; ISO C99 and later do not support implicit int}}
200 // Include these declarations here explicitly so we don't depend on system headers.
201 typedef struct __jmp_buf_tag
{} jmp_buf[1];
203 extern void longjmp (struct __jmp_buf_tag __env
[1], int __val
) __attribute__ ((noreturn
));
204 extern void _longjmp (struct __jmp_buf_tag __env
[1], int __val
) __attribute__ ((noreturn
));
210 longjmp(test30_j
, 1);
212 #if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__)
213 longjmp(test30_j
, 2);
215 _longjmp(test30_j
, 1);
219 typedef void test31_t(int status
);
220 void test31(test31_t
*callback
__attribute__((noreturn
)));
223 ^ (void) { while (1) { } }();
224 ^ (void) { if (j
) while (1) { } }();
232 // Test that 'static inline' functions are only analyzed for CFG-based warnings
233 // when they are used.
234 static inline int si_has_missing_return(void) {} // expected-warning{{non-void function does not return a value}}
235 static inline int si_has_missing_return_2(void) {}; // expected-warning{{non-void function does not return a value}}
236 static inline int si_forward(void);
237 static inline int si_has_missing_return_3(int x
) {
239 return si_has_missing_return_3(x
+1);
240 } // expected-warning{{non-void function does not return a value in all control paths}}
242 int test_static_inline(int x
) {
244 return x
? si_has_missing_return_2() : si_has_missing_return_3(x
);
246 static inline int si_forward(void) {} // expected-warning{{non-void function does not return a value}}
248 // Test warnings on ignored qualifiers on return types.
249 const int ignored_c_quals(void); // expected-warning{{'const' type qualifier on return type has no effect}}
250 const volatile int ignored_cv_quals(void); // expected-warning{{'const volatile' type qualifiers on return type have no effect}}
251 char* const volatile restrict
ignored_cvr_quals(void); // expected-warning{{'const volatile restrict' type qualifiers on return type have no effect}}
253 typedef const int CI
;
254 CI
ignored_quals_typedef(void);
256 const CI
ignored_quals_typedef_2(void); // expected-warning{{'const' type qualifier}}
258 // Test that for switch(enum) that if the switch statement covers all the cases
259 // that we don't consider that for -Wreturn-type.
260 enum Cases
{ C1
, C2
, C3
, C4
};
261 int test_enum_cases(enum Cases C
) {
270 // PR12318 - Don't give a may reach end of non-void function warning.
274 } else if ( x
== 2 || 1) {
289 __builtin_unreachable();
299 void abort(void) __attribute__((noreturn
));
300 #define av_assert0(cond) do {\
315 int PR19074_positive(int x
) {
322 } // expected-warning {{non-void function does not return a value in all control paths}}
324 // sizeof(long) test.
325 int sizeof_long(void) {
326 if (sizeof(long) == 4)
328 if (sizeof(long) == 8)
332 int return_statement_expression(void) {
341 } // no-warning (used to be "non-void function does not return a value in all control paths")