Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
Douglas Gregor | 43c79c2 | 2009-12-09 00:47:37 +0000 | [diff] [blame] | 2 | |
John McCall | 1de8533 | 2011-05-11 07:19:11 +0000 | [diff] [blame] | 3 | // Reachability tests have to come first because they get suppressed |
| 4 | // if any errors have occurred. |
| 5 | namespace test5 { |
| 6 | struct A { |
| 7 | __attribute__((noreturn)) void fail(); |
| 8 | void nofail(); |
| 9 | } a; |
| 10 | |
| 11 | int &test1() { |
| 12 | a.nofail(); |
| 13 | } // expected-warning {{control reaches end of non-void function}} |
| 14 | |
| 15 | int &test2() { |
| 16 | a.fail(); |
| 17 | } |
| 18 | } |
| 19 | |
Douglas Gregor | 43c79c2 | 2009-12-09 00:47:37 +0000 | [diff] [blame] | 20 | // PR5620 |
| 21 | void f0() __attribute__((__noreturn__)); |
| 22 | void f1(void (*)()); |
| 23 | void f2() { f1(f0); } |
| 24 | |
| 25 | // Taking the address of a noreturn function |
| 26 | void test_f0a() { |
| 27 | void (*fp)() = f0; |
| 28 | void (*fp1)() __attribute__((noreturn)) = f0; |
| 29 | } |
| 30 | |
| 31 | // Taking the address of an overloaded noreturn function |
| 32 | void f0(int) __attribute__((__noreturn__)); |
| 33 | |
| 34 | void test_f0b() { |
| 35 | void (*fp)() = f0; |
| 36 | void (*fp1)() __attribute__((noreturn)) = f0; |
| 37 | } |
| 38 | |
| 39 | // No-returned function pointers |
| 40 | typedef void (* noreturn_fp)() __attribute__((noreturn)); |
| 41 | |
| 42 | void f3(noreturn_fp); // expected-note{{candidate function}} |
| 43 | |
| 44 | void test_f3() { |
| 45 | f3(f0); // okay |
| 46 | f3(f2); // expected-error{{no matching function for call}} |
| 47 | } |
Nuno Lopes | f75b830 | 2009-12-23 23:40:33 +0000 | [diff] [blame] | 48 | |
| 49 | |
| 50 | class xpto { |
Anders Carlsson | 5d1d7ae | 2010-09-03 00:25:02 +0000 | [diff] [blame] | 51 | int blah() __attribute__((noreturn)); |
Nuno Lopes | f75b830 | 2009-12-23 23:40:33 +0000 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | int xpto::blah() { |
| 55 | return 3; // expected-warning {{function 'blah' declared 'noreturn' should not return}} |
| 56 | } |
Douglas Gregor | 71074fd | 2012-09-13 21:56:43 +0000 | [diff] [blame] | 57 | |
| 58 | // PR12948 |
| 59 | |
| 60 | namespace PR12948 { |
| 61 | template<int> |
| 62 | void foo() __attribute__((__noreturn__)); |
| 63 | |
| 64 | template<int> |
| 65 | void foo() { |
| 66 | while (1) continue; |
| 67 | } |
| 68 | |
| 69 | void bar() __attribute__((__noreturn__)); |
| 70 | |
| 71 | void bar() { |
| 72 | foo<0>(); |
| 73 | } |
| 74 | |
| 75 | |
| 76 | void baz() __attribute__((__noreturn__)); |
| 77 | typedef void voidfn(); |
| 78 | voidfn baz; |
| 79 | |
| 80 | template<typename> void wibble() __attribute__((__noreturn__)); |
| 81 | template<typename> voidfn wibble; |
| 82 | } |