blob: 3f064a01c867b6f10be771059056ef1bb2a04753 [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -verify -fsyntax-only %s
Daniel Dunbard3f2c102008-10-19 02:04:16 +00002
3static void (*fp0)(void) __attribute__((noreturn));
4
Chris Lattnere0303582010-01-09 20:43:19 +00005void fatal();
6
Daniel Dunbard3f2c102008-10-19 02:04:16 +00007static void __attribute__((noreturn)) f0(void) {
8 fatal();
Mike Stump29813c32009-09-16 00:39:34 +00009} // expected-warning {{function declared 'noreturn' should not return}}
Daniel Dunbard3f2c102008-10-19 02:04:16 +000010
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)}}
Mike Stumpf7c41da2009-04-29 00:43:21 +000017
18void f3() __attribute__((noreturn));
Mike Stumpf7c41da2009-04-29 00:43:21 +000019void f3() {
Douglas Gregor9dc9c372009-10-21 15:46:01 +000020 return; // expected-warning {{function 'f3' declared 'noreturn' should not return}}
Mike Stumpf7c41da2009-04-29 00:43:21 +000021}
22
Douglas Gregor9dc9c372009-10-21 15:46:01 +000023#pragma clang diagnostic error "-Winvalid-noreturn"
Chris Lattner86625872009-05-31 19:32:13 +000024
25void f4() __attribute__((noreturn));
26void f4() {
Douglas Gregor9dc9c372009-10-21 15:46:01 +000027 return; // expected-error {{function 'f4' declared 'noreturn' should not return}}
Chris Lattner86625872009-05-31 19:32:13 +000028}
29
Douglas Gregor47259d92009-08-05 19:03:35 +000030// PR4685
31extern void f5 (unsigned long) __attribute__ ((__noreturn__));
32
33void
34f5 (unsigned long size)
35{
36
Mike Stump29813c32009-09-16 00:39:34 +000037}
Mike Stumpedd722e2009-12-15 18:02:45 +000038
39// PR2461
40__attribute__((noreturn)) void f(__attribute__((noreturn)) void (*x)(void)) {
41 x();
42}