1 // RUN: %clang_cc1 -fsyntax-only -Wno-strict-prototypes -verify %s -fblocks
7 int (^PFR
) (int) = 0; // OK
16 if (PFR
== (int (^) (int))IFP
) // OK
28 return PFR
!= IFP
; // OK
31 int test2(double (^S
)()) {
32 double (^I
)(int) = (void*) S
;
33 (void*)I
= (void *)S
; // expected-error {{assignment to cast is illegal, lvalue casts are not supported}}
41 return (void*)I
== (void *)S
;
44 int^ x
; // expected-error {{block pointer to non-function type is invalid}}
45 int^^ x1
; // expected-error {{block pointer to non-function type is invalid}} expected-error {{block pointer to non-function type is invalid}}
48 char *^ y
; // expected-error {{block pointer to non-function type is invalid}}
53 enum {NSBIRLazilyAllocated
= 0};
58 case NSBIRLazilyAllocated
: // is an integer constant expression.
70 bar(^{ test5g
= 1; });
73 const char*test6(void) {
80 int test7(void (^p
)()) {
87 ^{ goto somelabel
; }(); // expected-error {{use of undeclared label 'somelabel'}}
91 goto somelabel
; // expected-error {{use of undeclared label 'somelabel'}}
98 ^{ case 42: ; }(); // expected-error {{'case' statement not in switch statement}}
105 ^{ break; }(); // expected-error {{'break' statement not in loop or switch statement}}
109 ^{ break; }(); // expected-error {{'break' statement not in loop or switch statement}}
112 void (^test12f
)(void);
114 test12f
= ^test12f
; // expected-error {{type name requires a specifier or qualifier}} expected-error {{expected expression}}
121 return X
+4; // References outer block's "X", so outer block is constant.
127 static void *P
= ^{ // expected-error {{initializer element is not a compile-time constant}}
130 // References test14's "X": outer block is non-constant.
138 void foo(long (^comp
)()) { // expected-note{{passing argument to parameter 'comp' here}}
141 void (^test15f
)(void);
143 foo(^{ return LESS
; }); // expected-error {{incompatible block pointer types passing 'int (^)(void)' to parameter of type 'long (^)()'}}
146 __block
int test16i
; // expected-error {{__block attribute not allowed, only allowed on local variables}}
148 void test16(__block
int i
) { // expected-error {{__block attribute not allowed, only allowed on local variables}}
150 extern __block
double extern_var
; // expected-error {{__block attribute not allowed, only allowed on local variables}}
151 static __block
char * pch
; // expected-error {{__block attribute not allowed, only allowed on local variables}}
152 __block
int a
[size
]; // expected-error {{__block attribute not allowed on declaration with a variably modified type}}
153 __block
int (*ap
)[size
]; // expected-error {{__block attribute not allowed on declaration with a variably modified type}}
167 (void)(bp
> rp
); // expected-error {{invalid operands}}
168 (void)(bp
> 0); // expected-error {{invalid operands}}
169 (void)(bp
> bp
); // expected-error {{invalid operands}}
170 (void)(bp
> vp
); // expected-error {{invalid operands}}
171 f(1 ? bp
: rp
); // expected-error {{incompatible operand types ('void (^)(int)' and 'void (*)(int)')}}
172 (void)(bp
== 1); // expected-error {{invalid operands to binary expression}}
174 (void)(1 == bp
); // expected-error {{invalid operands to binary expression}}
176 (void)(bp
< 1); // expected-error {{invalid operands to binary expression}}
177 (void)(bp
< 0); // expected-error {{invalid operands to binary expression}}
178 (void)(1 < bp
); // expected-error {{invalid operands to binary expression}}
179 (void)(0 < bp
); // expected-error {{invalid operands to binary expression}}
183 void (^const blockA
)(void) = ^{ }; // expected-note {{variable 'blockA' declared const here}}
184 blockA
= ^{ }; // expected-error {{cannot assign to variable 'blockA' with const-qualified type 'void (^const)(void)}}
188 goto L0
; // expected-error {{cannot jump}}
190 __block
int x
; // expected-note {{jump bypasses setup of __block variable}}
199 int vla
[n
]; // expected-note {{declared here}}
200 int (*vm
)[n
] = 0; // expected-note {{declared here}}
203 (void)vla
[1]; // expected-error {{cannot refer to declaration with a variably modified type inside block}}
204 (void)(vm
+1); // expected-error {{cannot refer to declaration with a variably modified type inside block}}
209 int a
[7]; // expected-note {{declared here}}
210 __block
int b
[10]; // expected-note {{declared here}}
213 (void)a
[1]; // expected-error {{cannot refer to declaration with an array type inside block}}
214 (void)b
[1]; // expected-error {{cannot refer to declaration with an array type inside block}}
218 const char * (^func
)(void) = ^{ return __func__
; };
219 const char * (^function
)(void) = ^{ return __FUNCTION__
; };
220 const char * (^pretty
)(void) = ^{ return __PRETTY_FUNCTION__
; };