1// RUN: %clang_cc1 -E %s -o %t.mm
2// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc %t.mm -o - | FileCheck %s
3// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc -fobjc-runtime=macosx-fragile-10.5 %s -o %t-rw.cpp
4// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"Class=void*" -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp
5// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc %s -o %t-modern-rw.cpp
6// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"Class=void*" -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-modern-rw.cpp
7
8// rdar://11375908
9typedef unsigned long size_t;
10
11// rdar: // 11006566
12
13void I( void (^)(void));
14void (^noop)(void);
15
16void nothing();
17int printf(const char*, ...);
18
19typedef void (^T) (void);
20
21void takeblock(T);
22int takeintint(int (^C)(int)) { return C(4); }
23
24T somefunction() {
25  if (^{ })
26    nothing();
27
28  noop = ^{};
29
30  noop = ^{printf("\nClosure\n"); };
31
32  I(^{ });
33
34  return ^{printf("\nClosure\n"); };
35}
36void test2() {
37  int x = 4;
38
39  takeblock(^{ printf("%d\n", x); });
40
41  while (1) {
42    takeblock(^{
43        while(1) break;  // ok
44      });
45    break;
46  }
47}
48
49void test4() {
50  void (^noop)(void) = ^{};
51  void (*noop2)() = 0;
52}
53
54void myfunc(int (^block)(int)) {}
55
56void myfunc3(const int *x);
57
58void test5() {
59  int a;
60
61  myfunc(^(int abcd) {
62      myfunc3(&a);
63      return 1;
64    });
65}
66
67void *X;
68
69static int global_x = 10;
70void (^global_block)(void) = ^{ printf("global x is %d\n", global_x); };
71
72// CHECK: static __global_block_block_impl_0 __global_global_block_block_impl_0((void *)__global_block_block_func_0, &__global_block_block_desc_0_DATA);
73// CHECK: void (*global_block)(void) = ((void (*)())&__global_global_block_block_impl_0);
74
75typedef void (^void_block_t)(void);
76
77static const void_block_t myBlock = ^{ };
78
79static const void_block_t myBlock2 = ^ void(void) { };
80