2009-03-24 10:24:46 +08:00
|
|
|
// RUN: clang-cc -fsyntax-only -verify %s -fblocks
|
2008-09-06 06:11:13 +08:00
|
|
|
void donotwarn();
|
|
|
|
|
|
|
|
int (^IFP) ();
|
|
|
|
int (^II) (int);
|
|
|
|
int test1() {
|
2009-04-01 09:17:39 +08:00
|
|
|
int (^PFR) (int) = 0; // OK
|
|
|
|
PFR = II; // OK
|
2008-09-06 06:11:13 +08:00
|
|
|
|
2009-04-01 09:17:39 +08:00
|
|
|
if (PFR == II) // OK
|
|
|
|
donotwarn();
|
2008-09-06 06:11:13 +08:00
|
|
|
|
2009-04-01 09:17:39 +08:00
|
|
|
if (PFR == IFP) // expected-error {{comparison of distinct block types}}
|
|
|
|
donotwarn();
|
2008-09-06 06:11:13 +08:00
|
|
|
|
2009-04-01 09:17:39 +08:00
|
|
|
if (PFR == (int (^) (int))IFP) // OK
|
|
|
|
donotwarn();
|
2008-09-06 06:11:13 +08:00
|
|
|
|
2009-04-01 09:17:39 +08:00
|
|
|
if (PFR == 0) // OK
|
|
|
|
donotwarn();
|
2008-09-06 06:11:13 +08:00
|
|
|
|
2009-04-01 09:17:39 +08:00
|
|
|
if (PFR) // OK
|
|
|
|
donotwarn();
|
2008-09-06 06:11:13 +08:00
|
|
|
|
2009-04-01 09:17:39 +08:00
|
|
|
if (!PFR) // OK
|
|
|
|
donotwarn();
|
2008-09-06 06:11:13 +08:00
|
|
|
|
2009-04-01 09:17:39 +08:00
|
|
|
return PFR != IFP; // expected-error {{comparison of distinct block types}}
|
2008-09-06 06:11:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int test2(double (^S)()) {
|
2009-04-01 09:17:39 +08:00
|
|
|
double (^I)(int) = (void*) S;
|
|
|
|
(void*)I = (void *)S; // expected-error {{assignment to cast is illegal, lvalue casts are not supported}}
|
2008-09-06 06:11:13 +08:00
|
|
|
|
2009-04-01 09:17:39 +08:00
|
|
|
void *pv = I;
|
2008-09-06 06:11:13 +08:00
|
|
|
|
2009-04-01 09:17:39 +08:00
|
|
|
pv = S;
|
2008-09-06 06:11:13 +08:00
|
|
|
|
2009-04-01 09:17:39 +08:00
|
|
|
I(1);
|
|
|
|
|
|
|
|
return (void*)I == (void *)S;
|
2008-09-06 06:11:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int^ x; // expected-error {{block pointer to non-function type is invalid}}
|
2009-02-08 15:59:54 +08:00
|
|
|
int^^ x1; // expected-error {{block pointer to non-function type is invalid}} expected-error {{block pointer to non-function type is invalid}}
|
2008-09-06 06:11:13 +08:00
|
|
|
|
|
|
|
int test3() {
|
2009-04-01 09:17:39 +08:00
|
|
|
char *^ y; // expected-error {{block pointer to non-function type is invalid}}
|
2008-09-06 06:11:13 +08:00
|
|
|
}
|
|
|
|
|
2008-09-28 13:30:26 +08:00
|
|
|
|
|
|
|
|
|
|
|
enum {NSBIRLazilyAllocated = 0};
|
|
|
|
|
|
|
|
int test4(int argc) { // rdar://6251437
|
|
|
|
^{
|
|
|
|
switch (argc) {
|
|
|
|
case NSBIRLazilyAllocated: // is an integer constant expression.
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}();
|
|
|
|
return 0;
|
|
|
|
}
|
2008-10-20 13:16:36 +08:00
|
|
|
|
|
|
|
|
|
|
|
// rdar://6257721 - reference to static/global is byref by default.
|
|
|
|
static int test5g;
|
|
|
|
void test5() {
|
|
|
|
bar(^{ test5g = 1; });
|
|
|
|
}
|
|
|
|
|
2008-12-05 07:50:19 +08:00
|
|
|
// rdar://6405429 - __func__ in a block refers to the containing function name.
|
|
|
|
const char*test6() {
|
2009-04-01 09:17:39 +08:00
|
|
|
return ^{
|
|
|
|
return __func__;
|
|
|
|
} ();
|
2008-12-05 07:50:19 +08:00
|
|
|
}
|
|
|
|
|
2009-04-01 09:17:39 +08:00
|
|
|
// radr://6732116 - block comparisons
|
2009-04-19 03:32:54 +08:00
|
|
|
void (^test7a)();
|
|
|
|
int test7(void (^p)()) {
|
|
|
|
return test7a == p;
|
2009-04-01 09:17:39 +08:00
|
|
|
}
|
2009-04-19 03:32:54 +08:00
|
|
|
|
|
|
|
|
|
|
|
void test8() {
|
|
|
|
somelabel:
|
|
|
|
// FIXME: This should say "jump out of block not legal" when gotos are allowed.
|
|
|
|
^{ goto somelabel; }(); // expected-error {{goto not allowed in block literal}}
|
|
|
|
}
|
|
|
|
|
|
|
|
void test9() {
|
|
|
|
goto somelabel; // expected-error {{use of undeclared label 'somelabel'}}
|
|
|
|
^{ somelabel: ; }();
|
|
|
|
}
|
|
|
|
|
2009-04-19 04:10:59 +08:00
|
|
|
void test10(int i) {
|
|
|
|
switch (i) {
|
|
|
|
case 41: ;
|
|
|
|
^{ case 42: ; }(); // expected-error {{'case' statement not in switch statement}}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void test11(int i) {
|
|
|
|
switch (i) {
|
|
|
|
case 41: ;
|
|
|
|
^{ break; }(); // expected-error {{'break' statement not in loop or switch statement}}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (; i < 100; ++i)
|
|
|
|
^{ break; }(); // expected-error {{'break' statement not in loop or switch statement}}
|
|
|
|
}
|
|
|
|
|
2009-04-19 03:32:54 +08:00
|
|
|
|
2009-04-19 04:12:56 +08:00
|
|
|
void (^test12f)(void);
|
|
|
|
void test12() {
|
|
|
|
test12f = ^test12f; // expected-error {{type name requires a specifier or qualifier}} expected-error {{expected expression}}
|
|
|
|
}
|
|
|
|
|