freebsd-dev/test/Sema/block-literal.c

90 lines
1.6 KiB
C
Raw Normal View History

2010-01-01 10:34:51 +00:00
// RUN: %clang_cc1 -fsyntax-only %s -verify -fblocks
2009-06-02 17:58:47 +00:00
void I( void (^)(void));
void (^noop)(void);
void nothing();
int printf(const char*, ...);
typedef void (^T) (void);
2009-10-14 18:03:49 +00:00
void takeblock(T);
2009-06-02 17:58:47 +00:00
int takeintint(int (^C)(int)) { return C(4); }
T somefunction() {
2009-10-14 18:03:49 +00:00
if (^{ })
nothing();
2009-06-02 17:58:47 +00:00
2009-10-14 18:03:49 +00:00
noop = ^{};
2009-06-02 17:58:47 +00:00
2009-10-14 18:03:49 +00:00
noop = ^{printf("\nClosure\n"); };
2009-06-02 17:58:47 +00:00
2009-10-14 18:03:49 +00:00
I(^{ });
2009-06-02 17:58:47 +00:00
2009-10-14 18:03:49 +00:00
return ^{printf("\nClosure\n"); };
2009-06-02 17:58:47 +00:00
}
void test2() {
2009-10-14 18:03:49 +00:00
int x = 4;
2009-06-02 17:58:47 +00:00
2009-10-14 18:03:49 +00:00
takeblock(^{ printf("%d\n", x); });
2009-06-02 17:58:47 +00:00
while (1) {
2009-10-14 18:03:49 +00:00
takeblock(^{
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-23 11:10:26 +00:00
goto foo; // expected-error {{use of undeclared label 'foo'}}
a: goto a; // ok
2009-10-14 18:03:49 +00:00
});
2009-06-02 17:58:47 +00:00
break;
2009-10-14 18:03:49 +00:00
}
2009-06-02 17:58:47 +00:00
2009-10-14 18:03:49 +00:00
foo:
takeblock(^{ x = 4; }); // expected-error {{variable is not assignable (missing __block type specifier)}}
2009-06-02 17:58:47 +00:00
__block y = 7; // expected-warning {{type specifier missing, defaults to 'int'}}
2009-10-14 18:03:49 +00:00
takeblock(^{ y = 8; });
2009-06-02 17:58:47 +00:00
}
void (^test3())(void) {
return ^{};
}
void test4() {
void (^noop)(void) = ^{};
void (*noop2)() = 0;
}
void myfunc(int (^block)(int)) {}
void myfunc3(const int *x);
void test5() {
2009-10-14 18:03:49 +00:00
int a;
2009-06-02 17:58:47 +00:00
2009-10-14 18:03:49 +00:00
myfunc(^(int abcd) {
myfunc3(&a);
return 1;
2009-06-02 17:58:47 +00:00
});
}
void *X;
void test_arguments() {
int y;
int (^c)(char);
(1 ? c : 0)('x');
(1 ? 0 : c)('x');
(1 ? c : c)('x');
}
static int global_x = 10;
void (^global_block)(void) = ^{ printf("global x is %d\n", global_x); };
typedef void (^void_block_t)(void);
static const void_block_t myBlock = ^{ };
static const void_block_t myBlock2 = ^ void(void) { };