Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s -fblocks |
Douglas Gregor | b65f242 | 2008-12-01 19:48:06 +0000 | [diff] [blame] | 2 | |
| 3 | void tovoid(void*); |
| 4 | |
| 5 | void tovoid_test(int (^f)(int, int)) { |
| 6 | tovoid(f); |
| 7 | } |
Anders Carlsson | 5e57831 | 2009-05-26 02:03:20 +0000 | [diff] [blame] | 8 | |
| 9 | void reference_lvalue_test(int& (^f)()) { |
| 10 | f() = 10; |
| 11 | } |
John McCall | ea1471e | 2010-05-20 01:18:31 +0000 | [diff] [blame^] | 12 | |
| 13 | // PR 7165 |
| 14 | namespace test1 { |
| 15 | void g(void (^)()); |
| 16 | struct Foo { |
| 17 | void foo(); |
| 18 | void test() { |
| 19 | (void) ^{ foo(); }; |
| 20 | } |
| 21 | }; |
| 22 | } |
| 23 | |
| 24 | namespace 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 | } |