Tareq A. Siraj | 6afcf88 | 2013-04-16 19:37:38 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s -fblocks |
| 2 | |
| 3 | void test_gotos() { |
| 4 | goto L1; // expected-error {{use of undeclared label 'L1'}} |
| 5 | goto L3; // OK |
| 6 | #pragma clang __debug captured |
| 7 | { |
| 8 | L1: |
| 9 | goto L2; // OK |
| 10 | L2: |
| 11 | goto L3; // expected-error {{use of undeclared label 'L3'}} |
| 12 | } |
| 13 | L3: ; |
| 14 | } |
| 15 | |
| 16 | void test_break_continue() { |
| 17 | while (1) { |
| 18 | #pragma clang __debug captured |
| 19 | { |
| 20 | break; // expected-error {{'break' statement not in loop or switch statement}} |
| 21 | continue; // expected-error {{'continue' statement not in loop statement}} |
| 22 | } |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | void test_return() { |
| 27 | while (1) { |
| 28 | #pragma clang __debug captured |
| 29 | { |
| 30 | return; // expected-error {{cannot return from default captured statement}} |
| 31 | } |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | void test_nest() { |
| 36 | int x; |
| 37 | #pragma clang __debug captured |
| 38 | { |
| 39 | int y; |
| 40 | #pragma clang __debug captured |
| 41 | { |
| 42 | int z; |
| 43 | #pragma clang __debug captured |
| 44 | { |
| 45 | x = z = y; // OK |
| 46 | } |
| 47 | } |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | void test_nest_block() { |
Ben Langmuir | 524387a | 2013-05-09 19:17:11 +0000 | [diff] [blame] | 52 | __block int x; // expected-note {{'x' declared here}} |
Tareq A. Siraj | 6afcf88 | 2013-04-16 19:37:38 +0000 | [diff] [blame] | 53 | int y; |
| 54 | ^{ |
| 55 | int z; |
| 56 | #pragma clang __debug captured |
| 57 | { |
Ben Langmuir | 524387a | 2013-05-09 19:17:11 +0000 | [diff] [blame] | 58 | x = y; // expected-error{{__block variable 'x' cannot be captured in a captured statement}} |
Tareq A. Siraj | 6afcf88 | 2013-04-16 19:37:38 +0000 | [diff] [blame] | 59 | y = z; // expected-error{{variable is not assignable (missing __block type specifier)}} |
| 60 | z = y; // OK |
| 61 | } |
| 62 | }(); |
| 63 | |
Ben Langmuir | 524387a | 2013-05-09 19:17:11 +0000 | [diff] [blame] | 64 | __block int a; // expected-note 2 {{'a' declared here}} |
Tareq A. Siraj | 6afcf88 | 2013-04-16 19:37:38 +0000 | [diff] [blame] | 65 | int b; |
| 66 | #pragma clang __debug captured |
| 67 | { |
| 68 | __block int c; |
| 69 | int d; |
| 70 | ^{ |
Ben Langmuir | 524387a | 2013-05-09 19:17:11 +0000 | [diff] [blame] | 71 | a = b; // expected-error{{__block variable 'a' cannot be captured in a captured statement}} |
Tareq A. Siraj | 6afcf88 | 2013-04-16 19:37:38 +0000 | [diff] [blame] | 72 | b = d; // OK - Consistent with block inside a lambda |
Ben Langmuir | 524387a | 2013-05-09 19:17:11 +0000 | [diff] [blame] | 73 | c = a; // expected-error{{__block variable 'a' cannot be captured in a captured statement}} |
| 74 | c = d; // OK |
Tareq A. Siraj | 6afcf88 | 2013-04-16 19:37:38 +0000 | [diff] [blame] | 75 | d = b; // expected-error{{variable is not assignable (missing __block type specifier)}} |
| 76 | }(); |
| 77 | } |
| 78 | } |