• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// RUN: %clang_cc1 -pedantic-errors -fblocks -std=c++1y -emit-pch %s -o %t-cxx11
2// RUN: %clang_cc1 -ast-print -pedantic-errors -fblocks -std=c++1y -include-pch %t-cxx11  %s | FileCheck -check-prefix=CHECK-PRINT %s
3
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}
29
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
36template<typename T>
37int init_capture(T t) {
38  return [&, x(t)] { return sizeof(x); };
39}
40
41struct X {
42  template <typename T> X(T) {}
43};
44struct Y { Y(const X &x = [] {}); };
45
46#else
47
48// CHECK-PRINT: T add_slowly
49// CHECK-PRINT: return [=, &y]
50template float add_slowly(const float&, const float&);
51
52int add(int x, int y) {
53  return add_int_slowly_twice(x, y) + sum_array(4) + to_block_pointer(5);
54}
55
56// CHECK-PRINT: inline int add_int_slowly_twice
57// CHECK-PRINT: lambda = [&](int z)
58
59// CHECK-PRINT: init_capture
60// CHECK-PRINT: [&, x(t)]
61
62X x = [] {};
63
64#endif
65