1f4a2713aSLionel Sambuc// RUN: %clang_cc1 -pedantic-errors -fblocks -std=c++1y -emit-pch %s -o %t-cxx1y 2f4a2713aSLionel Sambuc// RUN: %clang_cc1 -ast-print -pedantic-errors -fblocks -std=c++1y -include-pch %t-cxx1y %s | FileCheck -check-prefix=CHECK-PRINT %s 3f4a2713aSLionel Sambuc 4f4a2713aSLionel Sambuc#ifndef HEADER_INCLUDED 5f4a2713aSLionel Sambuc 6f4a2713aSLionel Sambuc#define HEADER_INCLUDED 7f4a2713aSLionel Sambuctemplate<typename T> 8f4a2713aSLionel SambucT add_slowly(const T& x, const T &y) { 9f4a2713aSLionel Sambuc return [](auto z, int y = 0) { return z + y; }(5); 10f4a2713aSLionel Sambuc}; 11f4a2713aSLionel Sambuc 12f4a2713aSLionel Sambucinline int add_int_slowly_twice(int x, int y) { 13f4a2713aSLionel Sambuc int i = add_slowly(x, y); 14f4a2713aSLionel Sambuc auto lambda = [](auto z) { return z + z; }; 15f4a2713aSLionel Sambuc return i + lambda(y); 16f4a2713aSLionel Sambuc} 17f4a2713aSLionel Sambuc 18f4a2713aSLionel Sambucinline int sum_array(int n) { 19f4a2713aSLionel Sambuc auto lambda = [](auto N) -> int { 20f4a2713aSLionel Sambuc int sum = 0; 21f4a2713aSLionel Sambuc int array[5] = { 1, 2, 3, 4, 5}; 22f4a2713aSLionel Sambuc 23f4a2713aSLionel Sambuc for (unsigned I = 0; I < N; ++I) 24f4a2713aSLionel Sambuc sum += array[N]; 25f4a2713aSLionel Sambuc return sum; 26f4a2713aSLionel Sambuc }; 27f4a2713aSLionel Sambuc 28f4a2713aSLionel Sambuc return lambda(n); 29f4a2713aSLionel Sambuc} 30f4a2713aSLionel Sambuc 31f4a2713aSLionel Sambucinline int to_block_pointer(int n) { 32f4a2713aSLionel Sambuc auto lambda = [=](int m) { return n + m; }; 33f4a2713aSLionel Sambuc int (^block)(int) = lambda; 34f4a2713aSLionel Sambuc return block(17); 35f4a2713aSLionel Sambuc} 36f4a2713aSLionel Sambuc 37f4a2713aSLionel Sambuctemplate<typename T> 38f4a2713aSLionel Sambucint init_capture(T t) { 39f4a2713aSLionel Sambuc return [&, x(t)] { return sizeof(x); }; 40f4a2713aSLionel Sambuc} 41f4a2713aSLionel Sambuc 42f4a2713aSLionel Sambuc#else 43f4a2713aSLionel Sambuc 44f4a2713aSLionel Sambuc// CHECK-PRINT: T add_slowly 45f4a2713aSLionel Sambuc// CHECK-PRINT: return [] 46f4a2713aSLionel Sambuctemplate float add_slowly(const float&, const float&); 47f4a2713aSLionel Sambuc 48f4a2713aSLionel Sambucint add(int x, int y) { 49f4a2713aSLionel Sambuc return add_int_slowly_twice(x, y) + sum_array(4) + to_block_pointer(5); 50f4a2713aSLionel Sambuc} 51f4a2713aSLionel Sambuc 52f4a2713aSLionel Sambuc// CHECK-PRINT: inline int add_int_slowly_twice 53*0a6a1f1dSLionel Sambuc// CHECK-PRINT: lambda = [] (type-parameter-0-0 z 54f4a2713aSLionel Sambuc 55f4a2713aSLionel Sambuc// CHECK-PRINT: init_capture 56f4a2713aSLionel Sambuc// CHECK-PRINT: [&, x( t )] 57f4a2713aSLionel Sambuc 58f4a2713aSLionel Sambuc#endif 59