blob: adbff553e6086e06c502b67af1f2619600464839 [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s -fblocks
Douglas Gregorb65f2422008-12-01 19:48:06 +00002
3void tovoid(void*);
4
5void tovoid_test(int (^f)(int, int)) {
6 tovoid(f);
7}
Anders Carlsson5e578312009-05-26 02:03:20 +00008
9void reference_lvalue_test(int& (^f)()) {
10 f() = 10;
11}
John McCallea1471e2010-05-20 01:18:31 +000012
13// PR 7165
14namespace test1 {
15 void g(void (^)());
16 struct Foo {
17 void foo();
18 void test() {
19 (void) ^{ foo(); };
20 }
21 };
22}
23
24namespace test2 {
25 int repeat(int value, int (^block)(int), unsigned n) {
26 while (n--) value = block(value);
27 return value;
28 }
29
30 class Power {
31 int base;
32
33 public:
34 Power(int base) : base(base) {}
35 int calculate(unsigned n) {
36 return repeat(1, ^(int v) { return v * base; }, n);
37 }
38 };
39
40 int test() {
41 return Power(2).calculate(10);
42 }
43}
Fariborz Jahanian79255612010-09-03 21:36:02 +000044
45// rdar: // 8382559
46namespace radar8382559 {
47 void func(bool& outHasProperty);
48
49 int test3() {
50 __attribute__((__blocks__(byref))) bool hasProperty = false;
Fariborz Jahanian469a20d2010-09-03 23:07:53 +000051 bool has = true;
52
Fariborz Jahanian79255612010-09-03 21:36:02 +000053 bool (^b)() = ^ {
54 func(hasProperty);
55 if (hasProperty)
56 hasProperty = 0;
Fariborz Jahanian469a20d2010-09-03 23:07:53 +000057 if (has)
58 hasProperty = 1;
Fariborz Jahanian79255612010-09-03 21:36:02 +000059 return hasProperty;
60 };
61 func(hasProperty);
Fariborz Jahanian469a20d2010-09-03 23:07:53 +000062 func(has);
Fariborz Jahanian79255612010-09-03 21:36:02 +000063 b();
64 if (hasProperty)
65 hasProperty = 1;
Fariborz Jahanian469a20d2010-09-03 23:07:53 +000066 if (has)
67 has = 2;
Fariborz Jahanian79255612010-09-03 21:36:02 +000068 return hasProperty = 1;
69 }
70}