blob: c00ec638075204fefcbeaf6689b9430ca95a93ca [file] [log] [blame]
Douglas Gregorf6e2e022012-02-16 01:06:16 +00001// RUN: %clang_cc1 -pedantic-errors -fblocks -std=c++11 -emit-pch %s -o %t-cxx11
2// RUN: %clang_cc1 -ast-print -pedantic-errors -fblocks -std=c++11 -include-pch %t-cxx11 %s | FileCheck -check-prefix=CHECK-PRINT %s
Douglas Gregor9d36f5d2012-02-14 17:54:36 +00003
4#ifndef HEADER_INCLUDED
5
6#define HEADER_INCLUDED
7template<typename T>
8T add_slowly(const T& x, const T &y) {
9 return [=, &y] { return x + y; }();
10};
11
12inline int add_int_slowly_twice(int x, int y) {
13 int i = add_slowly(x, y);
14 auto lambda = [&](int z) { return x + z; };
15 return i + lambda(y);
16}
17
18inline int sum_array(int n) {
19 int array[5] = { 1, 2, 3, 4, 5};
20 auto lambda = [=](int N) -> int {
21 int sum = 0;
22 for (unsigned I = 0; I < N; ++I)
23 sum += array[N];
24 return sum;
25 };
26
27 return lambda(n);
28}
Douglas Gregorf6e2e022012-02-16 01:06:16 +000029
30inline int to_block_pointer(int n) {
31 auto lambda = [=](int m) { return n + m; };
32 int (^block)(int) = lambda;
33 return block(17);
34}
35
Douglas Gregor9d36f5d2012-02-14 17:54:36 +000036#else
37
Douglas Gregor9d665042012-02-14 18:47:12 +000038// CHECK-PRINT: T add_slowly
Douglas Gregor9d36f5d2012-02-14 17:54:36 +000039// CHECK-PRINT: return [=, &y]
40template float add_slowly(const float&, const float&);
41
Douglas Gregor9d36f5d2012-02-14 17:54:36 +000042int add(int x, int y) {
Douglas Gregorf6e2e022012-02-16 01:06:16 +000043 return add_int_slowly_twice(x, y) + sum_array(4) + to_block_pointer(5);
Douglas Gregor9d36f5d2012-02-14 17:54:36 +000044}
45
46// CHECK-PRINT: inline int add_int_slowly_twice
47// CHECK-PRINT: lambda = [&] (int z)
48#endif