Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -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() { | ||||
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 15 | if (^{ }) |
16 | nothing(); | ||||
Steve Naroff | 61f40a2 | 2008-09-10 19:17:48 +0000 | [diff] [blame] | 17 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 18 | noop = ^{}; |
Steve Naroff | 61f40a2 | 2008-09-10 19:17:48 +0000 | [diff] [blame] | 19 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 20 | noop = ^{printf("\nClosure\n"); }; |
Steve Naroff | 61f40a2 | 2008-09-10 19:17:48 +0000 | [diff] [blame] | 21 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 22 | I(^{ }); |
Steve Naroff | 61f40a2 | 2008-09-10 19:17:48 +0000 | [diff] [blame] | 23 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 24 | return ^{printf("\nClosure\n"); }; |
Steve Naroff | 61f40a2 | 2008-09-10 19:17:48 +0000 | [diff] [blame] | 25 | } |
26 | void test2() { | ||||
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 27 | int x = 4; |
Steve Naroff | 61f40a2 | 2008-09-10 19:17:48 +0000 | [diff] [blame] | 28 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 32 | takeblock(^{ |
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 | ||||
Mike Stump | a3899eb | 2010-01-19 23:08:01 +0000 | [diff] [blame] | 36 | goto foo; // expected-error {{use of undeclared label 'foo'}} |
37 | a: goto a; // ok | ||||
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 38 | }); |
Steve Naroff | 61f40a2 | 2008-09-10 19:17:48 +0000 | [diff] [blame] | 39 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 40 | } |
Steve Naroff | 61f40a2 | 2008-09-10 19:17:48 +0000 | [diff] [blame] | 41 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 42 | foo: |
43 | 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] | 44 | __block y = 7; // expected-warning {{type specifier missing, defaults to 'int'}} |
Mike Stump | 0e88b16 | 2009-08-27 00:29:21 +0000 | [diff] [blame] | 45 | takeblock(^{ y = 8; }); |
Steve Naroff | 61f40a2 | 2008-09-10 19:17:48 +0000 | [diff] [blame] | 46 | } |
47 | |||||
48 | |||||
49 | void (^test3())(void) { | ||||
Mike Stump | 397195b | 2009-04-17 00:09:41 +0000 | [diff] [blame] | 50 | return ^{}; |
Steve Naroff | 61f40a2 | 2008-09-10 19:17:48 +0000 | [diff] [blame] | 51 | } |
52 | |||||
53 | void test4() { | ||||
54 | void (^noop)(void) = ^{}; | ||||
55 | void (*noop2)() = 0; | ||||
56 | } | ||||
57 | |||||
Steve Naroff | 4f6a7d7 | 2008-09-26 14:41:28 +0000 | [diff] [blame] | 58 | void myfunc(int (^block)(int)) {} |
59 | |||||
Eli Friedman | 5fdeae1 | 2009-03-22 23:00:19 +0000 | [diff] [blame] | 60 | void myfunc3(const int *x); |
Steve Naroff | 4f6a7d7 | 2008-09-26 14:41:28 +0000 | [diff] [blame] | 61 | |
62 | void test5() { | ||||
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 63 | int a; |
Steve Naroff | 4f6a7d7 | 2008-09-26 14:41:28 +0000 | [diff] [blame] | 64 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 65 | myfunc(^(int abcd) { |
66 | myfunc3(&a); | ||||
67 | return 1; | ||||
Steve Naroff | 4f6a7d7 | 2008-09-26 14:41:28 +0000 | [diff] [blame] | 68 | }); |
69 | } | ||||
70 | |||||
Steve Naroff | 61f40a2 | 2008-09-10 19:17:48 +0000 | [diff] [blame] | 71 | void *X; |
72 | |||||
73 | void test_arguments() { | ||||
Steve Naroff | 61f40a2 | 2008-09-10 19:17:48 +0000 | [diff] [blame] | 74 | int y; |
Steve Naroff | 61f40a2 | 2008-09-10 19:17:48 +0000 | [diff] [blame] | 75 | int (^c)(char); |
76 | (1 ? c : 0)('x'); | ||||
77 | (1 ? 0 : c)('x'); | ||||
78 | |||||
79 | (1 ? c : c)('x'); | ||||
80 | } | ||||
81 | |||||
Steve Naroff | 8af6a45 | 2008-10-02 17:12:56 +0000 | [diff] [blame] | 82 | static int global_x = 10; |
83 | void (^global_block)(void) = ^{ printf("global x is %d\n", global_x); }; | ||||
84 | |||||
Steve Naroff | 3aaa482 | 2009-04-16 19:02:57 +0000 | [diff] [blame] | 85 | typedef void (^void_block_t)(void); |
86 | |||||
87 | static const void_block_t myBlock = ^{ }; | ||||
88 | |||||
89 | static const void_block_t myBlock2 = ^ void(void) { }; |