2009-12-16 04:14:24 +08:00
|
|
|
// RUN: %clang_cc1 -fsyntax-only %s -verify -fblocks
|
2008-09-11 03:17:48 +08:00
|
|
|
|
|
|
|
void I( void (^)(void));
|
|
|
|
void (^noop)(void);
|
|
|
|
|
2022-02-04 05:39:21 +08:00
|
|
|
void nothing(void);
|
2008-09-11 03:17:48 +08:00
|
|
|
int printf(const char*, ...);
|
|
|
|
|
|
|
|
typedef void (^T) (void);
|
|
|
|
|
2009-08-27 08:29:21 +08:00
|
|
|
void takeblock(T);
|
2008-09-11 03:17:48 +08:00
|
|
|
int takeintint(int (^C)(int)) { return C(4); }
|
|
|
|
|
2022-02-04 05:39:21 +08:00
|
|
|
T somefunction(void) {
|
2009-09-09 23:08:12 +08:00
|
|
|
if (^{ })
|
|
|
|
nothing();
|
2008-09-11 03:17:48 +08:00
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
noop = ^{};
|
2008-09-11 03:17:48 +08:00
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
noop = ^{printf("\nClosure\n"); };
|
2008-09-11 03:17:48 +08:00
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
I(^{ });
|
2008-09-11 03:17:48 +08:00
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
return ^{printf("\nClosure\n"); };
|
2008-09-11 03:17:48 +08:00
|
|
|
}
|
2022-02-04 05:39:21 +08:00
|
|
|
void test2(void) {
|
2009-09-09 23:08:12 +08:00
|
|
|
int x = 4;
|
2008-09-11 03:17:48 +08:00
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
takeblock(^{ printf("%d\n", x); });
|
2008-09-11 03:17:48 +08:00
|
|
|
|
|
|
|
while (1) {
|
2022-05-04 20:34:26 +08:00
|
|
|
takeblock(^{
|
2009-09-09 23:08:12 +08:00
|
|
|
break; // expected-error {{'break' statement not in loop or switch statement}}
|
|
|
|
continue; // expected-error {{'continue' statement not in loop statement}}
|
|
|
|
while(1) break; // ok
|
2010-01-20 07:08:01 +08:00
|
|
|
goto foo; // expected-error {{use of undeclared label 'foo'}}
|
|
|
|
a: goto a; // ok
|
2009-09-09 23:08:12 +08:00
|
|
|
});
|
2008-09-11 03:17:48 +08:00
|
|
|
break;
|
2009-09-09 23:08:12 +08:00
|
|
|
}
|
2008-09-11 03:17:48 +08:00
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
foo:
|
|
|
|
takeblock(^{ x = 4; }); // expected-error {{variable is not assignable (missing __block type specifier)}}
|
2022-05-04 20:34:26 +08:00
|
|
|
__block y = 7; // expected-error {{type specifier missing, defaults to 'int'}}
|
2009-08-27 08:29:21 +08:00
|
|
|
takeblock(^{ y = 8; });
|
2008-09-11 03:17:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-05-04 20:34:26 +08:00
|
|
|
void (^test3(void))(void) {
|
2009-04-17 08:09:41 +08:00
|
|
|
return ^{};
|
2008-09-11 03:17:48 +08:00
|
|
|
}
|
|
|
|
|
2022-02-04 05:39:21 +08:00
|
|
|
void test4(void) {
|
2008-09-11 03:17:48 +08:00
|
|
|
void (^noop)(void) = ^{};
|
2022-02-04 05:39:21 +08:00
|
|
|
void (*noop2)(void) = 0;
|
2008-09-11 03:17:48 +08:00
|
|
|
}
|
|
|
|
|
2008-09-26 22:41:28 +08:00
|
|
|
void myfunc(int (^block)(int)) {}
|
|
|
|
|
2009-03-23 07:00:19 +08:00
|
|
|
void myfunc3(const int *x);
|
2008-09-26 22:41:28 +08:00
|
|
|
|
2022-02-04 05:39:21 +08:00
|
|
|
void test5(void) {
|
2009-09-09 23:08:12 +08:00
|
|
|
int a;
|
2008-09-26 22:41:28 +08:00
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
myfunc(^(int abcd) {
|
|
|
|
myfunc3(&a);
|
|
|
|
return 1;
|
2008-09-26 22:41:28 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2008-09-11 03:17:48 +08:00
|
|
|
void *X;
|
|
|
|
|
2022-02-04 05:39:21 +08:00
|
|
|
void test_arguments(void) {
|
2008-09-11 03:17:48 +08:00
|
|
|
int y;
|
|
|
|
int (^c)(char);
|
|
|
|
(1 ? c : 0)('x');
|
|
|
|
(1 ? 0 : c)('x');
|
|
|
|
|
|
|
|
(1 ? c : c)('x');
|
|
|
|
}
|
|
|
|
|
2008-10-03 01:12:56 +08:00
|
|
|
static int global_x = 10;
|
|
|
|
void (^global_block)(void) = ^{ printf("global x is %d\n", global_x); };
|
|
|
|
|
2009-04-17 03:02:57 +08:00
|
|
|
typedef void (^void_block_t)(void);
|
|
|
|
|
|
|
|
static const void_block_t myBlock = ^{ };
|
|
|
|
|
2022-05-04 20:34:26 +08:00
|
|
|
static const void_block_t myBlock2 = ^ void(void) { };
|