1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only %s -verify -fblocks 2*f4a2713aSLionel Sambuc 3*f4a2713aSLionel Sambuc void I( void (^)(void)); 4*f4a2713aSLionel Sambuc void (^noop)(void); 5*f4a2713aSLionel Sambuc 6*f4a2713aSLionel Sambuc void nothing(); 7*f4a2713aSLionel Sambuc int printf(const char*, ...); 8*f4a2713aSLionel Sambuc 9*f4a2713aSLionel Sambuc typedef void (^T) (void); 10*f4a2713aSLionel Sambuc 11*f4a2713aSLionel Sambuc void takeblock(T); 12*f4a2713aSLionel Sambuc int takeintint(int (^C)(int)) { return C(4); } 13*f4a2713aSLionel Sambuc somefunction()14*f4a2713aSLionel SambucT somefunction() { 15*f4a2713aSLionel Sambuc if (^{ }) 16*f4a2713aSLionel Sambuc nothing(); 17*f4a2713aSLionel Sambuc 18*f4a2713aSLionel Sambuc noop = ^{}; 19*f4a2713aSLionel Sambuc 20*f4a2713aSLionel Sambuc noop = ^{printf("\nClosure\n"); }; 21*f4a2713aSLionel Sambuc 22*f4a2713aSLionel Sambuc I(^{ }); 23*f4a2713aSLionel Sambuc 24*f4a2713aSLionel Sambuc return ^{printf("\nClosure\n"); }; 25*f4a2713aSLionel Sambuc } test2()26*f4a2713aSLionel Sambucvoid test2() { 27*f4a2713aSLionel Sambuc int x = 4; 28*f4a2713aSLionel Sambuc 29*f4a2713aSLionel Sambuc takeblock(^{ printf("%d\n", x); }); 30*f4a2713aSLionel Sambuc 31*f4a2713aSLionel Sambuc while (1) { 32*f4a2713aSLionel Sambuc takeblock(^{ 33*f4a2713aSLionel Sambuc break; // expected-error {{'break' statement not in loop or switch statement}} 34*f4a2713aSLionel Sambuc continue; // expected-error {{'continue' statement not in loop statement}} 35*f4a2713aSLionel Sambuc while(1) break; // ok 36*f4a2713aSLionel Sambuc goto foo; // expected-error {{use of undeclared label 'foo'}} 37*f4a2713aSLionel Sambuc a: goto a; // ok 38*f4a2713aSLionel Sambuc }); 39*f4a2713aSLionel Sambuc break; 40*f4a2713aSLionel Sambuc } 41*f4a2713aSLionel Sambuc 42*f4a2713aSLionel Sambuc foo: 43*f4a2713aSLionel Sambuc takeblock(^{ x = 4; }); // expected-error {{variable is not assignable (missing __block type specifier)}} 44*f4a2713aSLionel Sambuc __block y = 7; // expected-warning {{type specifier missing, defaults to 'int'}} 45*f4a2713aSLionel Sambuc takeblock(^{ y = 8; }); 46*f4a2713aSLionel Sambuc } 47*f4a2713aSLionel Sambuc 48*f4a2713aSLionel Sambuc test3()49*f4a2713aSLionel Sambucvoid (^test3())(void) { 50*f4a2713aSLionel Sambuc return ^{}; 51*f4a2713aSLionel Sambuc } 52*f4a2713aSLionel Sambuc test4()53*f4a2713aSLionel Sambucvoid test4() { 54*f4a2713aSLionel Sambuc void (^noop)(void) = ^{}; 55*f4a2713aSLionel Sambuc void (*noop2)() = 0; 56*f4a2713aSLionel Sambuc } 57*f4a2713aSLionel Sambuc 58*f4a2713aSLionel Sambuc void myfunc(int (^block)(int)) {} 59*f4a2713aSLionel Sambuc 60*f4a2713aSLionel Sambuc void myfunc3(const int *x); 61*f4a2713aSLionel Sambuc test5()62*f4a2713aSLionel Sambucvoid test5() { 63*f4a2713aSLionel Sambuc int a; 64*f4a2713aSLionel Sambuc 65*f4a2713aSLionel Sambuc myfunc(^(int abcd) { 66*f4a2713aSLionel Sambuc myfunc3(&a); 67*f4a2713aSLionel Sambuc return 1; 68*f4a2713aSLionel Sambuc }); 69*f4a2713aSLionel Sambuc } 70*f4a2713aSLionel Sambuc 71*f4a2713aSLionel Sambuc void *X; 72*f4a2713aSLionel Sambuc test_arguments()73*f4a2713aSLionel Sambucvoid test_arguments() { 74*f4a2713aSLionel Sambuc int y; 75*f4a2713aSLionel Sambuc int (^c)(char); 76*f4a2713aSLionel Sambuc (1 ? c : 0)('x'); 77*f4a2713aSLionel Sambuc (1 ? 0 : c)('x'); 78*f4a2713aSLionel Sambuc 79*f4a2713aSLionel Sambuc (1 ? c : c)('x'); 80*f4a2713aSLionel Sambuc } 81*f4a2713aSLionel Sambuc 82*f4a2713aSLionel Sambuc static int global_x = 10; 83*f4a2713aSLionel Sambuc void (^global_block)(void) = ^{ printf("global x is %d\n", global_x); }; 84*f4a2713aSLionel Sambuc 85*f4a2713aSLionel Sambuc typedef void (^void_block_t)(void); 86*f4a2713aSLionel Sambuc 87*f4a2713aSLionel Sambuc static const void_block_t myBlock = ^{ }; 88*f4a2713aSLionel Sambuc 89*f4a2713aSLionel Sambuc static const void_block_t myBlock2 = ^ void(void) { }; 90