1 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s -fblocks
5 void tovoid_test(int (^f
)(int, int)) {
9 void reference_lvalue_test(int& (^f
)()) {
25 int repeat(int value
, int (^block
)(int), unsigned n
) {
26 while (n
--) value
= block(value
);
34 Power(int base
) : base(base
) {}
35 int calculate(unsigned n
) {
36 return repeat(1, ^(int v
) { return v
* base
; }, n
);
41 return Power(2).calculate(10);
46 namespace radar8382559
{
47 void func(bool& outHasProperty
);
50 __attribute__((__blocks__(byref
))) bool hasProperty
= false;
68 return hasProperty
= 1;
72 // Move __block variables to the heap when possible.
76 MoveOnly(const MoveOnly
&) = delete;
84 // Don't crash after failing to build a block due to a capture of an
85 // invalid declaration.
87 struct B
{ // expected-note 2 {{candidate constructor}}
89 B(int); // expected-note {{candidate constructor}}
92 void use_block(void (^)());
93 void use_block_2(void (^)(), const B
&a
);
96 B x
; // expected-error {{no matching constructor for initialization}}
99 use_block_2(^{ (void) y
; }, x
);
107 // Ensure that we can end function bodies while parsing an
108 // expression that requires an explicitly-tracked cleanup object
109 // (i.e. a block literal).
111 // The nested function body in this test case is a template
112 // instantiation. The template function has to be constexpr because
113 // we'll otherwise delay its instantiation to the end of the
116 template <class T
> constexpr int func() { return 0; }
117 void run(void (^)(), int);
120 int aCapturedVar
= 0;
121 run(^{ (void) aCapturedVar
; }, func
<int>());
125 // The nested function body in this test case is a method of a local
128 void run(void (^)(), void (^)());
130 int aCapturedVar
= 0;
131 run(^{ (void) aCapturedVar
; },
132 ^{ struct A
{ static void foo() {} };
137 // The nested function body in this test case is a lambda invocation
140 void run(void (^)(), void (^)());
142 int aCapturedVar
= 0;
143 run(^{ (void) aCapturedVar
; },
144 ^{ struct A
{ static void foo() {} };
153 auto some_block
= ^{ (void)s
; };
157 void static_data_member() {
160 static int x
; // expected-error {{static data member 'x' not allowed in local class 'X'}}
164 static int z
; // expected-error {{static data member 'z' not allowed in local struct 'Z'}}