Anders Carlsson | abea951 | 2011-02-28 00:40:07 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify %s |
Sebastian Redl | 972041f | 2009-04-27 20:27:31 +0000 | [diff] [blame] | 2 | |
John McCall | 7c2342d | 2010-03-10 11:27:22 +0000 | [diff] [blame] | 3 | struct A; // expected-note 4 {{forward declaration of 'A'}} |
Sebastian Redl | 972041f | 2009-04-27 20:27:31 +0000 | [diff] [blame] | 4 | |
Chandler Carruth | 45f11b7 | 2011-02-18 23:59:51 +0000 | [diff] [blame] | 5 | struct Abstract { virtual void f() = 0; }; // expected-note {{unimplemented pure virtual method 'f'}} |
Sebastian Redl | fef9f59 | 2009-04-27 21:03:30 +0000 | [diff] [blame] | 6 | |
Sebastian Redl | 972041f | 2009-04-27 20:27:31 +0000 | [diff] [blame] | 7 | void trys() { |
| 8 | try { |
| 9 | } catch(int i) { // expected-note {{previous definition}} |
| 10 | int j = i; |
| 11 | int i; // expected-error {{redefinition of 'i'}} |
| 12 | } catch(float i) { |
| 13 | } catch(void v) { // expected-error {{cannot catch incomplete type 'void'}} |
John McCall | 7c2342d | 2010-03-10 11:27:22 +0000 | [diff] [blame] | 14 | } catch(A a) { // expected-error {{cannot catch incomplete type 'A'}} |
Douglas Gregor | ecd7b04 | 2012-01-24 19:01:26 +0000 | [diff] [blame] | 15 | } catch(A *a) { // expected-error {{cannot catch pointer to incomplete type 'A'}} |
| 16 | } catch(A &a) { // expected-error {{cannot catch reference to incomplete type 'A'}} |
Sebastian Redl | fef9f59 | 2009-04-27 21:03:30 +0000 | [diff] [blame] | 17 | } catch(Abstract) { // expected-error {{variable type 'Abstract' is an abstract class}} |
Sebastian Redl | 972041f | 2009-04-27 20:27:31 +0000 | [diff] [blame] | 18 | } catch(...) { |
| 19 | int j = i; // expected-error {{use of undeclared identifier 'i'}} |
| 20 | } |
| 21 | |
| 22 | try { |
| 23 | } catch(...) { // expected-error {{catch-all handler must come last}} |
| 24 | } catch(int) { |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | void throws() { |
| 29 | throw; |
| 30 | throw 0; |
| 31 | throw throw; // expected-error {{cannot throw object of incomplete type 'void'}} |
John McCall | 7c2342d | 2010-03-10 11:27:22 +0000 | [diff] [blame] | 32 | throw (A*)0; // expected-error {{cannot throw pointer to object of incomplete type 'A'}} |
Sebastian Redl | 972041f | 2009-04-27 20:27:31 +0000 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | void jumps() { |
| 36 | l1: |
| 37 | goto l5; |
Richard Trieu | 2fe9b7f | 2011-12-15 00:38:15 +0000 | [diff] [blame] | 38 | goto l4; // expected-error {{goto into protected scope}} |
| 39 | goto l3; // expected-error {{goto into protected scope}} |
| 40 | goto l2; // expected-error {{goto into protected scope}} |
Sebastian Redl | 972041f | 2009-04-27 20:27:31 +0000 | [diff] [blame] | 41 | goto l1; |
| 42 | try { // expected-note 4 {{jump bypasses initialization of try block}} |
| 43 | l2: |
| 44 | goto l5; |
Richard Trieu | 2fe9b7f | 2011-12-15 00:38:15 +0000 | [diff] [blame] | 45 | goto l4; // expected-error {{goto into protected scope}} |
| 46 | goto l3; // expected-error {{goto into protected scope}} |
Sebastian Redl | 972041f | 2009-04-27 20:27:31 +0000 | [diff] [blame] | 47 | goto l2; |
| 48 | goto l1; |
| 49 | } catch(int) { // expected-note 4 {{jump bypasses initialization of catch block}} |
| 50 | l3: |
| 51 | goto l5; |
Richard Trieu | 2fe9b7f | 2011-12-15 00:38:15 +0000 | [diff] [blame] | 52 | goto l4; // expected-error {{goto into protected scope}} |
Sebastian Redl | 972041f | 2009-04-27 20:27:31 +0000 | [diff] [blame] | 53 | goto l3; |
Richard Trieu | 2fe9b7f | 2011-12-15 00:38:15 +0000 | [diff] [blame] | 54 | goto l2; // expected-error {{goto into protected scope}} |
Sebastian Redl | 972041f | 2009-04-27 20:27:31 +0000 | [diff] [blame] | 55 | goto l1; |
| 56 | } catch(...) { // expected-note 4 {{jump bypasses initialization of catch block}} |
| 57 | l4: |
| 58 | goto l5; |
| 59 | goto l4; |
Richard Trieu | 2fe9b7f | 2011-12-15 00:38:15 +0000 | [diff] [blame] | 60 | goto l3; // expected-error {{goto into protected scope}} |
| 61 | goto l2; // expected-error {{goto into protected scope}} |
Sebastian Redl | 972041f | 2009-04-27 20:27:31 +0000 | [diff] [blame] | 62 | goto l1; |
| 63 | } |
| 64 | l5: |
| 65 | goto l5; |
Richard Trieu | 2fe9b7f | 2011-12-15 00:38:15 +0000 | [diff] [blame] | 66 | goto l4; // expected-error {{goto into protected scope}} |
| 67 | goto l3; // expected-error {{goto into protected scope}} |
| 68 | goto l2; // expected-error {{goto into protected scope}} |
Sebastian Redl | 972041f | 2009-04-27 20:27:31 +0000 | [diff] [blame] | 69 | goto l1; |
| 70 | } |
Sebastian Redl | 13e8854 | 2009-04-27 21:33:24 +0000 | [diff] [blame] | 71 | |
| 72 | struct BadReturn { |
| 73 | BadReturn() try { |
| 74 | } catch(...) { |
| 75 | // Try to hide |
| 76 | try { |
| 77 | } catch(...) { |
| 78 | { |
| 79 | if (0) |
| 80 | return; // expected-error {{return in the catch of a function try block of a constructor is illegal}} |
| 81 | } |
| 82 | } |
| 83 | } |
| 84 | BadReturn(int); |
| 85 | }; |
| 86 | |
| 87 | BadReturn::BadReturn(int) try { |
| 88 | } catch(...) { |
| 89 | // Try to hide |
| 90 | try { |
| 91 | } catch(int) { |
| 92 | return; // expected-error {{return in the catch of a function try block of a constructor is illegal}} |
| 93 | } catch(...) { |
| 94 | { |
| 95 | if (0) |
| 96 | return; // expected-error {{return in the catch of a function try block of a constructor is illegal}} |
| 97 | } |
| 98 | } |
| 99 | } |
Douglas Gregor | bf422f9 | 2010-04-15 18:05:39 +0000 | [diff] [blame] | 100 | |
| 101 | // Cannot throw an abstract type. |
| 102 | class foo { |
| 103 | public: |
| 104 | foo() {} |
| 105 | void bar () { |
| 106 | throw *this; // expected-error{{cannot throw an object of abstract type 'foo'}} |
| 107 | } |
Chandler Carruth | 45f11b7 | 2011-02-18 23:59:51 +0000 | [diff] [blame] | 108 | virtual void test () = 0; // expected-note{{unimplemented pure virtual method 'test'}} |
Douglas Gregor | bf422f9 | 2010-04-15 18:05:39 +0000 | [diff] [blame] | 109 | }; |
Douglas Gregor | c0b3964 | 2010-04-15 23:40:53 +0000 | [diff] [blame] | 110 | |
| 111 | namespace PR6831 { |
| 112 | namespace NA { struct S; } |
| 113 | namespace NB { struct S; } |
| 114 | |
| 115 | void f() { |
| 116 | using namespace NA; |
| 117 | using namespace NB; |
| 118 | try { |
| 119 | } catch (int S) { |
| 120 | } |
| 121 | } |
| 122 | } |