Daniel Dunbar | d7d5f02 | 2009-03-24 02:24:46 +0000 | [diff] [blame] | 1 | // RUN: clang-cc -fsyntax-only %s -verify -fblocks |
Steve Naroff | 61f40a2 | 2008-09-10 19:17:48 +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 | |
Mike Stump | 0e88b16 | 2009-08-27 00:29:21 +0000 | [diff] [blame^] | 11 | void takeblock(T); |
Steve Naroff | 61f40a2 | 2008-09-10 19:17:48 +0000 | [diff] [blame] | 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 | |
Mike Stump | 397195b | 2009-04-17 00:09:41 +0000 | [diff] [blame] | 24 | return ^{printf("\nClosure\n"); }; |
Steve Naroff | 61f40a2 | 2008-09-10 19:17:48 +0000 | [diff] [blame] | 25 | } |
| 26 | void test2() { |
| 27 | int x = 4; |
| 28 | |
Mike Stump | 0e88b16 | 2009-08-27 00:29:21 +0000 | [diff] [blame^] | 29 | takeblock(^{ printf("%d\n", x); }); |
Steve Naroff | 61f40a2 | 2008-09-10 19:17:48 +0000 | [diff] [blame] | 30 | |
| 31 | while (1) { |
Mike Stump | 0e88b16 | 2009-08-27 00:29:21 +0000 | [diff] [blame^] | 32 | takeblock(^{ |
Steve Naroff | 61f40a2 | 2008-09-10 19:17:48 +0000 | [diff] [blame] | 33 | break; // expected-error {{'break' statement not in loop or switch statement}} |
| 34 | continue; // expected-error {{'continue' statement not in loop statement}} |
| 35 | while(1) break; // ok |
| 36 | goto foo; // expected-error {{goto not allowed}} |
| 37 | }); |
| 38 | break; |
| 39 | } |
| 40 | |
| 41 | foo: |
Mike Stump | 0e88b16 | 2009-08-27 00:29:21 +0000 | [diff] [blame^] | 42 | takeblock(^{ x = 4; }); // expected-error {{variable is not assignable (missing __block type specifier)}} |
Chris Lattner | 3f84ad2 | 2009-04-22 05:27:59 +0000 | [diff] [blame] | 43 | __block y = 7; // expected-warning {{type specifier missing, defaults to 'int'}} |
Mike Stump | 0e88b16 | 2009-08-27 00:29:21 +0000 | [diff] [blame^] | 44 | takeblock(^{ y = 8; }); |
Steve Naroff | 61f40a2 | 2008-09-10 19:17:48 +0000 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | |
| 48 | void (^test3())(void) { |
Mike Stump | 397195b | 2009-04-17 00:09:41 +0000 | [diff] [blame] | 49 | return ^{}; |
Steve Naroff | 61f40a2 | 2008-09-10 19:17:48 +0000 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | void test4() { |
| 53 | void (^noop)(void) = ^{}; |
| 54 | void (*noop2)() = 0; |
| 55 | } |
| 56 | |
Steve Naroff | 4f6a7d7 | 2008-09-26 14:41:28 +0000 | [diff] [blame] | 57 | void myfunc(int (^block)(int)) {} |
| 58 | |
Eli Friedman | 5fdeae1 | 2009-03-22 23:00:19 +0000 | [diff] [blame] | 59 | void myfunc3(const int *x); |
Steve Naroff | 4f6a7d7 | 2008-09-26 14:41:28 +0000 | [diff] [blame] | 60 | |
| 61 | void test5() { |
| 62 | int a; |
| 63 | |
| 64 | myfunc(^(int abcd) { |
| 65 | myfunc3(&a); |
| 66 | return 1; |
| 67 | }); |
| 68 | } |
| 69 | |
Steve Naroff | 61f40a2 | 2008-09-10 19:17:48 +0000 | [diff] [blame] | 70 | void *X; |
| 71 | |
| 72 | void test_arguments() { |
Steve Naroff | 61f40a2 | 2008-09-10 19:17:48 +0000 | [diff] [blame] | 73 | int y; |
Steve Naroff | 61f40a2 | 2008-09-10 19:17:48 +0000 | [diff] [blame] | 74 | int (^c)(char); |
| 75 | (1 ? c : 0)('x'); |
| 76 | (1 ? 0 : c)('x'); |
| 77 | |
| 78 | (1 ? c : c)('x'); |
| 79 | } |
| 80 | |
Steve Naroff | 8af6a45 | 2008-10-02 17:12:56 +0000 | [diff] [blame] | 81 | static int global_x = 10; |
| 82 | void (^global_block)(void) = ^{ printf("global x is %d\n", global_x); }; |
| 83 | |
Steve Naroff | 3aaa482 | 2009-04-16 19:02:57 +0000 | [diff] [blame] | 84 | typedef void (^void_block_t)(void); |
| 85 | |
| 86 | static const void_block_t myBlock = ^{ }; |
| 87 | |
| 88 | static const void_block_t myBlock2 = ^ void(void) { }; |