| 1 |
// RUN: %clang_cc1 -std=c23 -fdefer-ts -fsyntax-only -verify %s |
| 2 |
|
| 3 |
#define defer _Defer |
| 4 |
|
| 5 |
void a(); |
| 6 |
|
| 7 |
void f1() { |
| 8 |
defer { |
| 9 |
goto l1; |
| 10 |
l1: |
| 11 |
} |
| 12 |
|
| 13 |
defer { |
| 14 |
l2: |
| 15 |
goto l2; |
| 16 |
} |
| 17 |
} |
| 18 |
|
| 19 |
void f2() { |
| 20 |
goto l1; // expected-error {{cannot jump from this goto statement to its label}} |
| 21 |
defer { // expected-note {{jump enters a defer statement}} |
| 22 |
l1: |
| 23 |
} |
| 24 |
|
| 25 |
goto l2; // expected-error {{cannot jump from this goto statement to its label}} |
| 26 |
defer {} // expected-note {{jump bypasses defer statement}} |
| 27 |
l2: |
| 28 |
} |
| 29 |
|
| 30 |
void f3() { |
| 31 |
x: |
| 32 |
defer { // expected-note {{jump exits a defer statement}} |
| 33 |
goto x; // expected-error {{cannot jump from this goto statement to its label}} |
| 34 |
} |
| 35 |
} |
| 36 |
|
| 37 |
void f4() { |
| 38 |
defer { // expected-note {{jump exits a defer statement}} |
| 39 |
goto y; // expected-error {{cannot jump from this goto statement to its label}} |
| 40 |
} |
| 41 |
y: |
| 42 |
} |
| 43 |
|
| 44 |
void f5() { |
| 45 |
defer { // expected-note {{jump enters a defer statement}} |
| 46 |
l2: |
| 47 |
} |
| 48 |
goto l2; // expected-error {{cannot jump from this goto statement to its label}} |
| 49 |
} |
| 50 |
|
| 51 |
void f6() { |
| 52 |
goto b; // expected-error {{cannot jump from this goto statement to its label}} |
| 53 |
{ |
| 54 |
defer {} // expected-note {{jump bypasses defer statement}} |
| 55 |
b: |
| 56 |
} |
| 57 |
|
| 58 |
{ |
| 59 |
defer {} // expected-note {{jump bypasses defer statement}} |
| 60 |
b2: |
| 61 |
} |
| 62 |
goto b2; // expected-error {{cannot jump from this goto statement to its label}} |
| 63 |
} |
| 64 |
|
| 65 |
void f7() { |
| 66 |
defer { // expected-note {{jump bypasses defer statement}} |
| 67 |
goto cross1; // expected-error {{cannot jump from this goto statement to its label}} |
| 68 |
cross2: |
| 69 |
} |
| 70 |
defer { // expected-note {{jump exits a defer statement}} expected-note {{jump enters a defer statement}} |
| 71 |
goto cross2; // expected-error {{cannot jump from this goto statement to its label}} |
| 72 |
cross1: |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
void f8() { |
| 77 |
defer { |
| 78 |
return; // expected-error {{cannot return from a defer statement}} |
| 79 |
} |
| 80 |
|
| 81 |
{ |
| 82 |
defer { |
| 83 |
return; // expected-error {{cannot return from a defer statement}} |
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
switch (1) { |
| 88 |
case 1: defer { |
| 89 |
break; // expected-error {{cannot break out of a defer statement}} |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
for (;;) { |
| 94 |
defer { |
| 95 |
break; // expected-error {{cannot break out of a defer statement}} |
| 96 |
} |
| 97 |
} |
| 98 |
|
| 99 |
for (;;) { |
| 100 |
defer { |
| 101 |
continue; // expected-error {{cannot continue loop outside of enclosing defer statement}} |
| 102 |
} |
| 103 |
} |
| 104 |
|
| 105 |
switch (1) { |
| 106 |
defer {} // expected-note {{jump bypasses defer statement}} |
| 107 |
default: // expected-error {{cannot jump from switch statement to this case label}} |
| 108 |
defer {} |
| 109 |
break; |
| 110 |
} |
| 111 |
|
| 112 |
switch (1) { |
| 113 |
case 1: { |
| 114 |
defer { // expected-note {{jump enters a defer statement}} |
| 115 |
case 2: {} // expected-error {{cannot jump from switch statement to this case label}} |
| 116 |
} |
| 117 |
} |
| 118 |
} |
| 119 |
|
| 120 |
switch (1) { |
| 121 |
case 1: defer { |
| 122 |
switch (2) { case 2: break; } |
| 123 |
} |
| 124 |
} |
| 125 |
|
| 126 |
for (;;) { |
| 127 |
defer { for (;;) break; } |
| 128 |
} |
| 129 |
|
| 130 |
for (;;) { |
| 131 |
defer { for (;;) continue; } |
| 132 |
} |
| 133 |
} |
| 134 |
|
| 135 |
void f9() { |
| 136 |
{ |
| 137 |
defer {} |
| 138 |
goto l1; |
| 139 |
} |
| 140 |
l1: |
| 141 |
|
| 142 |
{ |
| 143 |
goto l2; |
| 144 |
defer {} |
| 145 |
} |
| 146 |
l2: |
| 147 |
|
| 148 |
{ |
| 149 |
{ defer {} } |
| 150 |
goto l3; |
| 151 |
} |
| 152 |
l3: |
| 153 |
|
| 154 |
{ |
| 155 |
defer {} |
| 156 |
{ goto l4; } |
| 157 |
} |
| 158 |
l4: |
| 159 |
} |
| 160 |
|
| 161 |
void f10(int i) { |
| 162 |
switch (i) { |
| 163 |
defer case 12: break; // expected-error {{cannot break out of a defer statement}} \ |
| 164 |
expected-error {{cannot jump from switch statement to this case label}} \ |
| 165 |
expected-note {{jump enters a defer statement}} \ |
| 166 |
expected-note {{jump bypasses defer statement}} |
| 167 |
|
| 168 |
defer default: break; // expected-error {{cannot break out of a defer statement}} \ |
| 169 |
expected-error {{cannot jump from switch statement to this case label}} \ |
| 170 |
expected-note {{jump enters a defer statement}} |
| 171 |
} |
| 172 |
} |