Mike Stump | edd722e | 2009-12-15 18:02:45 +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 | |
| 5 | static void __attribute__((noreturn)) f0(void) { |
| 6 | fatal(); |
Mike Stump | 29813c3 | 2009-09-16 00:39:34 +0000 | [diff] [blame] | 7 | } // expected-warning {{function declared 'noreturn' should not return}} |
Daniel Dunbar | d3f2c10 | 2008-10-19 02:04:16 +0000 | [diff] [blame] | 8 | |
| 9 | // On K&R |
| 10 | int f1() __attribute__((noreturn)); |
| 11 | |
| 12 | int g0 __attribute__((noreturn)); // expected-warning {{'noreturn' attribute only applies to function types}} |
| 13 | |
| 14 | 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] | 15 | |
| 16 | void f3() __attribute__((noreturn)); |
Mike Stump | f7c41da | 2009-04-29 00:43:21 +0000 | [diff] [blame] | 17 | void f3() { |
Douglas Gregor | 9dc9c37 | 2009-10-21 15:46:01 +0000 | [diff] [blame] | 18 | return; // expected-warning {{function 'f3' declared 'noreturn' should not return}} |
Mike Stump | f7c41da | 2009-04-29 00:43:21 +0000 | [diff] [blame] | 19 | } |
| 20 | |
Douglas Gregor | 9dc9c37 | 2009-10-21 15:46:01 +0000 | [diff] [blame] | 21 | #pragma clang diagnostic error "-Winvalid-noreturn" |
Chris Lattner | 8662587 | 2009-05-31 19:32:13 +0000 | [diff] [blame] | 22 | |
| 23 | void f4() __attribute__((noreturn)); |
| 24 | void f4() { |
Douglas Gregor | 9dc9c37 | 2009-10-21 15:46:01 +0000 | [diff] [blame] | 25 | return; // expected-error {{function 'f4' declared 'noreturn' should not return}} |
Chris Lattner | 8662587 | 2009-05-31 19:32:13 +0000 | [diff] [blame] | 26 | } |
| 27 | |
Douglas Gregor | 47259d9 | 2009-08-05 19:03:35 +0000 | [diff] [blame] | 28 | // PR4685 |
| 29 | extern void f5 (unsigned long) __attribute__ ((__noreturn__)); |
| 30 | |
| 31 | void |
| 32 | f5 (unsigned long size) |
| 33 | { |
| 34 | |
Mike Stump | 29813c3 | 2009-09-16 00:39:34 +0000 | [diff] [blame] | 35 | } |
Mike Stump | edd722e | 2009-12-15 18:02:45 +0000 | [diff] [blame^] | 36 | |
| 37 | // PR2461 |
| 38 | __attribute__((noreturn)) void f(__attribute__((noreturn)) void (*x)(void)) { |
| 39 | x(); |
| 40 | } |