[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / clang / test / Sema / captured-statements.c
blobfd907e766d549074a9618963d240f502768e57ee
1 // RUN: %clang_cc1 -fsyntax-only -verify %s -fblocks
3 void test_gotos(void) {
4 goto L1; // expected-error {{use of undeclared label 'L1'}}
5 goto L3; // OK
6 #pragma clang __debug captured
8 L1:
9 goto L2; // OK
10 L2:
11 goto L3; // expected-error {{use of undeclared label 'L3'}}
13 L3: ;
16 void test_break_continue(void) {
17 while (1) {
18 #pragma clang __debug captured
20 break; // expected-error {{'break' statement not in loop or switch statement}}
21 continue; // expected-error {{'continue' statement not in loop statement}}
26 void test_return(void) {
27 while (1) {
28 #pragma clang __debug captured
30 return; // expected-error {{cannot return from default captured statement}}
35 void test_nest(void) {
36 int x;
37 #pragma clang __debug captured
39 int y;
40 #pragma clang __debug captured
42 int z;
43 #pragma clang __debug captured
45 x = z = y; // OK
51 void test_nest_block(void) {
52 __block int x; // expected-note {{'x' declared here}}
53 int y;
55 int z;
56 #pragma clang __debug captured
58 x = y; // expected-error{{__block variable 'x' cannot be captured in a captured statement}}
59 y = z; // expected-error{{variable is not assignable (missing __block type specifier)}}
60 z = y; // OK
62 }();
64 __block int a; // expected-note 2 {{'a' declared here}}
65 int b;
66 #pragma clang __debug captured
68 int d;
70 a = b; // expected-error{{__block variable 'a' cannot be captured in a captured statement}}
71 a = b; // (duplicate diagnostic suppressed)
72 b = d; // OK - Consistent with block inside a lambda
73 }();
75 #pragma clang __debug captured
77 __block int c;
78 int d;
80 c = a; // expected-error{{__block variable 'a' cannot be captured in a captured statement}}
81 c = d; // OK
82 d = b; // expected-error{{variable is not assignable (missing __block type specifier)}}
83 }();