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);
45 namespace radar8382559
{
46 void func(bool& outHasProperty
);
49 __attribute__((__blocks__(byref
))) bool hasProperty
= false;
67 return hasProperty
= 1;
71 // Move __block variables to the heap when possible.
75 MoveOnly(const MoveOnly
&) = delete;
83 // Don't crash after failing to build a block due to a capture of an
84 // invalid declaration.
86 struct B
{ // expected-note 2 {{candidate constructor}}
88 B(int); // expected-note {{candidate constructor}}
91 void use_block(void (^)());
92 void use_block_2(void (^)(), const B
&a
);
95 B x
; // expected-error {{no matching constructor for initialization}}
98 use_block_2(^{ (void) y
; }, x
);
104 // Ensure that we can end function bodies while parsing an
105 // expression that requires an explicitly-tracked cleanup object
106 // (i.e. a block literal).
108 // The nested function body in this test case is a template
109 // instantiation. The template function has to be constexpr because
110 // we'll otherwise delay its instantiation to the end of the
113 template <class T
> constexpr int func() { return 0; }
114 void run(void (^)(), int);
117 int aCapturedVar
= 0;
118 run(^{ (void) aCapturedVar
; }, func
<int>());
122 // The nested function body in this test case is a method of a local
125 void run(void (^)(), void (^)());
127 int aCapturedVar
= 0;
128 run(^{ (void) aCapturedVar
; },
129 ^{ struct A
{ static void foo() {} };
134 // The nested function body in this test case is a lambda invocation
137 void run(void (^)(), void (^)());
139 int aCapturedVar
= 0;
140 run(^{ (void) aCapturedVar
; },
141 ^{ struct A
{ static void foo() {} };
150 auto some_block
= ^{ (void)s
; };
154 void static_data_member() {
157 static int x
; // expected-error {{static data member 'x' not allowed in local class 'X'}}
161 static int z
; // expected-error {{static data member 'z' not allowed in local struct 'Z'}}