Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -verify -fsyntax-only %s |
Daniel Dunbar | d3f2c10 | 2008-10-19 02:04:16 +0000 | [diff] [blame] | 2 | |
| 3 | static void (*fp0)(void) __attribute__((noreturn)); |
| 4 | |
Chris Lattner | e030358 | 2010-01-09 20:43:19 +0000 | [diff] [blame] | 5 | void fatal(); |
| 6 | |
Daniel Dunbar | d3f2c10 | 2008-10-19 02:04:16 +0000 | [diff] [blame] | 7 | static void __attribute__((noreturn)) f0(void) { |
| 8 | fatal(); |
Mike Stump | 29813c3 | 2009-09-16 00:39:34 +0000 | [diff] [blame] | 9 | } // expected-warning {{function declared 'noreturn' should not return}} |
Daniel Dunbar | d3f2c10 | 2008-10-19 02:04:16 +0000 | [diff] [blame] | 10 | |
| 11 | // On K&R |
| 12 | int f1() __attribute__((noreturn)); |
| 13 | |
John McCall | 04a67a6 | 2010-02-05 21:31:56 +0000 | [diff] [blame] | 14 | int g0 __attribute__((noreturn)); // expected-warning {{'noreturn' only applies to function types; type here is 'int'}} |
Daniel Dunbar | d3f2c10 | 2008-10-19 02:04:16 +0000 | [diff] [blame] | 15 | |
| 16 | int f2() __attribute__((noreturn(1, 2))); // expected-error {{attribute requires 0 argument(s)}} |
Mike Stump | f7c41da | 2009-04-29 00:43:21 +0000 | [diff] [blame] | 17 | |
| 18 | void f3() __attribute__((noreturn)); |
Mike Stump | f7c41da | 2009-04-29 00:43:21 +0000 | [diff] [blame] | 19 | void f3() { |
Douglas Gregor | 9dc9c37 | 2009-10-21 15:46:01 +0000 | [diff] [blame] | 20 | return; // expected-warning {{function 'f3' declared 'noreturn' should not return}} |
Mike Stump | f7c41da | 2009-04-29 00:43:21 +0000 | [diff] [blame] | 21 | } |
| 22 | |
Douglas Gregor | 9dc9c37 | 2009-10-21 15:46:01 +0000 | [diff] [blame] | 23 | #pragma clang diagnostic error "-Winvalid-noreturn" |
Chris Lattner | 8662587 | 2009-05-31 19:32:13 +0000 | [diff] [blame] | 24 | |
| 25 | void f4() __attribute__((noreturn)); |
| 26 | void f4() { |
Douglas Gregor | 9dc9c37 | 2009-10-21 15:46:01 +0000 | [diff] [blame] | 27 | return; // expected-error {{function 'f4' declared 'noreturn' should not return}} |
Chris Lattner | 8662587 | 2009-05-31 19:32:13 +0000 | [diff] [blame] | 28 | } |
| 29 | |
Douglas Gregor | 47259d9 | 2009-08-05 19:03:35 +0000 | [diff] [blame] | 30 | // PR4685 |
| 31 | extern void f5 (unsigned long) __attribute__ ((__noreturn__)); |
| 32 | |
| 33 | void |
| 34 | f5 (unsigned long size) |
| 35 | { |
| 36 | |
Mike Stump | 29813c3 | 2009-09-16 00:39:34 +0000 | [diff] [blame] | 37 | } |
Mike Stump | edd722e | 2009-12-15 18:02:45 +0000 | [diff] [blame] | 38 | |
| 39 | // PR2461 |
| 40 | __attribute__((noreturn)) void f(__attribute__((noreturn)) void (*x)(void)) { |
| 41 | x(); |
| 42 | } |
Abramo Bagnara | b1f1b26 | 2010-04-30 09:13:03 +0000 | [diff] [blame^] | 43 | |
| 44 | typedef void (*Fun)(void) __attribute__ ((noreturn(2))); // expected-error {{attribute requires 0 argument(s)}} |