llvm-project
62 строки · 1.4 Кб
1// RUN: %clang_cc1 -pedantic-errors -fblocks -std=c++1y -emit-pch %s -o %t-cxx1y
2// RUN: %clang_cc1 -ast-print -pedantic-errors -fblocks -std=c++1y -include-pch %t-cxx1y %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) {
9return [](auto z, int y = 0) { return z + y; }(5);
10};
11
12inline int add_int_slowly_twice(int x, int y) {
13int i = add_slowly(x, y);
14auto lambda = [](auto z) { return z + z; };
15return i + lambda(y);
16}
17
18inline int sum_array(int n) {
19auto lambda = [](auto N) -> int {
20int sum = 0;
21int array[5] = { 1, 2, 3, 4, 5};
22
23for (unsigned I = 0; I < N; ++I)
24sum += array[N];
25return sum;
26};
27
28return lambda(n);
29}
30
31inline int to_block_pointer(int n) {
32auto lambda = [=](int m) { return n + m; };
33int (^block)(int) = lambda;
34return block(17);
35}
36
37template<typename T>
38int init_capture(T t) {
39return [&, x(t)] { return sizeof(x); };
40}
41
42auto with_pack = [](auto ...xs){};
43
44#else
45
46// CHECK-PRINT: T add_slowly
47// CHECK-PRINT: return []
48template float add_slowly(const float&, const float&);
49
50int add(int x, int y) {
51return add_int_slowly_twice(x, y) + sum_array(4) + to_block_pointer(5);
52}
53
54// CHECK-PRINT: inline int add_int_slowly_twice
55// CHECK-PRINT: lambda = [](auto z
56
57// CHECK-PRINT: init_capture
58// CHECK-PRINT: [&, x(t)]
59
60void use_with_pack() { with_pack(1, 2, 3); }
61
62#endif
63