blob: 5c643fff718df83e2596632197b7ed938585c049 [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
Anders Carlsson5d1d7ae2010-09-03 00:25:02 +000012int f1() __attribute__((noreturn));
Daniel Dunbard3f2c102008-10-19 02:04:16 +000013
John McCall04a67a62010-02-05 21:31:56 +000014int g0 __attribute__((noreturn)); // expected-warning {{'noreturn' only applies to function types; type here is 'int'}}
Daniel Dunbard3f2c102008-10-19 02:04:16 +000015
John McCallbdc49d32011-03-02 12:15:05 +000016int f2() __attribute__((noreturn(1, 2))); // expected-error {{attribute takes no arguments}}
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}
Abramo Bagnarab1f1b262010-04-30 09:13:03 +000043
John McCallbdc49d32011-03-02 12:15:05 +000044typedef void (*Fun)(void) __attribute__ ((noreturn(2))); // expected-error {{attribute takes no arguments}}