Douglas Gregor | 1d2de76 | 2011-03-24 14:35:16 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wall -fblocks %s |
Douglas Gregor | c9977d0 | 2011-03-16 17:05:57 +0000 | [diff] [blame] | 2 | |
Douglas Gregor | 7cbc558 | 2011-03-14 21:19:51 +0000 | [diff] [blame] | 3 | // PR9463 |
| 4 | double *end; |
Douglas Gregor | bec7343 | 2011-03-23 21:19:43 +0000 | [diff] [blame] | 5 | void f(bool b1, bool b2) { |
Douglas Gregor | 7cbc558 | 2011-03-14 21:19:51 +0000 | [diff] [blame] | 6 | { |
Douglas Gregor | bec7343 | 2011-03-23 21:19:43 +0000 | [diff] [blame] | 7 | do { |
| 8 | int end = 0; |
| 9 | if (b2) { |
| 10 | do { |
| 11 | goto end; |
| 12 | } while (b2); |
| 13 | } |
| 14 | end = 1; |
| 15 | } while (b1); |
Douglas Gregor | 7cbc558 | 2011-03-14 21:19:51 +0000 | [diff] [blame] | 16 | } |
| 17 | |
| 18 | end: |
| 19 | return; |
| 20 | } |
| 21 | |
Douglas Gregor | fa7b8ce | 2011-03-24 10:35:39 +0000 | [diff] [blame] | 22 | namespace N { |
| 23 | float* end; |
| 24 | void f(bool b1, bool b2) { |
| 25 | { |
| 26 | do { |
| 27 | int end = 0; |
| 28 | if (b2) { |
| 29 | do { |
| 30 | goto end; |
| 31 | } while (b2); |
| 32 | } |
| 33 | end = 1; |
| 34 | } while (b1); |
| 35 | } |
| 36 | |
| 37 | end: |
| 38 | return; |
| 39 | } |
| 40 | } |
| 41 | |
Douglas Gregor | 7cbc558 | 2011-03-14 21:19:51 +0000 | [diff] [blame] | 42 | void g() { |
| 43 | end = 1; // expected-error{{assigning to 'double *' from incompatible type 'int'}} |
| 44 | } |
Douglas Gregor | 250e7a7 | 2011-03-16 16:39:03 +0000 | [diff] [blame] | 45 | |
| 46 | void h(int end) { |
| 47 | { |
| 48 | goto end; // expected-error{{use of undeclared label 'end'}} |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | void h2(int end) { |
| 53 | { |
| 54 | __label__ end; |
| 55 | goto end; |
| 56 | |
| 57 | end: |
| 58 | ::end = 0; |
| 59 | } |
Douglas Gregor | 1d2de76 | 2011-03-24 14:35:16 +0000 | [diff] [blame] | 60 | end: // expected-warning{{unused label 'end'}} |
Douglas Gregor | 250e7a7 | 2011-03-16 16:39:03 +0000 | [diff] [blame] | 61 | end = 1; |
| 62 | } |
| 63 | |
| 64 | class X { |
| 65 | public: |
| 66 | X(); |
| 67 | }; |
| 68 | |
| 69 | void rdar9135994() |
| 70 | { |
| 71 | X: |
| 72 | goto X; |
| 73 | } |
Douglas Gregor | c9977d0 | 2011-03-16 17:05:57 +0000 | [diff] [blame] | 74 | |
| 75 | namespace PR9495 { |
| 76 | struct NonPOD { NonPOD(); ~NonPOD(); }; |
| 77 | |
| 78 | void f(bool b) { |
| 79 | NonPOD np; |
| 80 | if (b) { |
| 81 | goto undeclared; // expected-error{{use of undeclared label 'undeclared'}} |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | void g() { |
| 86 | (void)^(bool b){ |
| 87 | NonPOD np; |
| 88 | if (b) { |
| 89 | goto undeclared; // expected-error{{use of undeclared label 'undeclared'}} |
| 90 | } |
| 91 | }; |
| 92 | } |
| 93 | } |
| 94 | |
Douglas Gregor | 1d2de76 | 2011-03-24 14:35:16 +0000 | [diff] [blame] | 95 | extern "C" { |
| 96 | void exit(int); |
| 97 | } |
Douglas Gregor | c9977d0 | 2011-03-16 17:05:57 +0000 | [diff] [blame] | 98 | |
Douglas Gregor | 1d2de76 | 2011-03-24 14:35:16 +0000 | [diff] [blame] | 99 | void f() { |
| 100 | { |
| 101 | goto exit; |
| 102 | } |
| 103 | exit: |
| 104 | return; |
| 105 | } |
Eli Friedman | 7badd24 | 2012-02-09 20:13:14 +0000 | [diff] [blame] | 106 | |
| 107 | namespace PR10620 { |
| 108 | struct S { |
| 109 | ~S() {} |
| 110 | }; |
| 111 | void g(const S& s) { |
| 112 | goto done; // expected-error {{goto into protected scope}} |
| 113 | const S s2(s); // expected-note {{jump bypasses variable initialization}} |
| 114 | done: |
| 115 | ; |
| 116 | } |
| 117 | } |
John McCall | 97b57a2 | 2012-04-13 01:08:17 +0000 | [diff] [blame] | 118 | |
| 119 | namespace test12 { |
| 120 | struct A { A(); A(const A&); ~A(); }; |
| 121 | void test(A a) { // expected-note {{jump enters lifetime of block}} FIXME: wierd location |
| 122 | goto lbl; // expected-error {{goto into protected scope}} |
| 123 | (void) ^{ (void) a; }; |
| 124 | lbl: |
| 125 | return; |
| 126 | } |
| 127 | } |