Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -rewrite-objc %s -fblocks -o - |
Fariborz Jahanian | 8a9e170 | 2009-12-15 17:30:20 +0000 | [diff] [blame] | 2 | |
| 3 | void I( void (^)(void)); |
| 4 | void (^noop)(void); |
| 5 | |
| 6 | void nothing(); |
| 7 | int printf(const char*, ...); |
| 8 | |
| 9 | typedef void (^T) (void); |
| 10 | |
| 11 | void takeblock(T); |
| 12 | int takeintint(int (^C)(int)) { return C(4); } |
| 13 | |
| 14 | T somefunction() { |
| 15 | if (^{ }) |
| 16 | nothing(); |
| 17 | |
| 18 | noop = ^{}; |
| 19 | |
| 20 | noop = ^{printf("\nClosure\n"); }; |
| 21 | |
| 22 | I(^{ }); |
| 23 | |
| 24 | return ^{printf("\nClosure\n"); }; |
| 25 | } |
| 26 | void test2() { |
| 27 | int x = 4; |
| 28 | |
| 29 | takeblock(^{ printf("%d\n", x); }); |
| 30 | |
| 31 | while (1) { |
| 32 | takeblock(^{ |
| 33 | while(1) break; // ok |
| 34 | }); |
| 35 | break; |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | |
| 40 | void (^test3())(void) { |
| 41 | return ^{}; |
| 42 | } |
| 43 | |
| 44 | void test4() { |
| 45 | void (^noop)(void) = ^{}; |
| 46 | void (*noop2)() = 0; |
| 47 | } |
| 48 | |
| 49 | void myfunc(int (^block)(int)) {} |
| 50 | |
| 51 | void myfunc3(const int *x); |
| 52 | |
| 53 | void test5() { |
| 54 | int a; |
| 55 | |
| 56 | myfunc(^(int abcd) { |
| 57 | myfunc3(&a); |
| 58 | return 1; |
| 59 | }); |
| 60 | } |
| 61 | |
| 62 | void *X; |
| 63 | |
| 64 | void test_arguments() { |
| 65 | int y; |
| 66 | int (^c)(char); |
| 67 | (1 ? c : 0)('x'); |
| 68 | (1 ? 0 : c)('x'); |
| 69 | |
| 70 | (1 ? c : c)('x'); |
| 71 | } |
| 72 | |
| 73 | static int global_x = 10; |
| 74 | void (^global_block)(void) = ^{ printf("global x is %d\n", global_x); }; |
| 75 | |
| 76 | typedef void (^void_block_t)(void); |
| 77 | |
| 78 | static const void_block_t myBlock = ^{ }; |
| 79 | |
| 80 | static const void_block_t myBlock2 = ^ void(void) { }; |