attr-noreturn.c revision e030358cc06e1cbce3c2e00ca67c946f9164b2a8
1// RUN: %clang_cc1 -verify -fsyntax-only %s
2
3static void (*fp0)(void) __attribute__((noreturn));
4
5void fatal();
6
7static void __attribute__((noreturn)) f0(void) {
8  fatal();
9} // expected-warning {{function declared 'noreturn' should not return}}
10
11// On K&R
12int f1() __attribute__((noreturn));
13
14int g0 __attribute__((noreturn)); // expected-warning {{'noreturn' attribute only applies to function types}}
15
16int f2() __attribute__((noreturn(1, 2))); // expected-error {{attribute requires 0 argument(s)}}
17
18void f3() __attribute__((noreturn));
19void f3() {
20  return;  // expected-warning {{function 'f3' declared 'noreturn' should not return}}
21}
22
23#pragma clang diagnostic error "-Winvalid-noreturn"
24
25void f4() __attribute__((noreturn));
26void f4() {
27  return;  // expected-error {{function 'f4' declared 'noreturn' should not return}}
28}
29
30// PR4685
31extern void f5 (unsigned long) __attribute__ ((__noreturn__));
32
33void
34f5 (unsigned long size)
35{
36
37}
38
39// PR2461
40__attribute__((noreturn)) void f(__attribute__((noreturn)) void (*x)(void)) {
41  x();
42}
43