Home | History | Annotate | Download | only in expr.prim.lambda
      1 // RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify
      2 
      3 void print();
      4 
      5 template<typename T, typename... Ts>
      6 void print(T first, Ts... rest) {
      7   (void)first;
      8   print(rest...);
      9 }
     10 
     11 template<typename... Ts>
     12 void unsupported(Ts ...values) {
     13   auto unsup = [values] {}; // expected-error{{unexpanded function parameter pack capture is unsupported}}
     14 }
     15 
     16 template<typename... Ts>
     17 void implicit_capture(Ts ...values) {
     18   auto implicit = [&] { print(values...); };
     19   implicit();
     20 }
     21 
     22 template<typename... Ts>
     23 void do_print(Ts... values) {
     24   auto bycopy = [values...]() { print(values...); };
     25   bycopy();
     26   auto byref = [&values...]() { print(values...); };
     27   byref();
     28 
     29   auto bycopy2 = [=]() { print(values...); };
     30   bycopy2();
     31   auto byref2 = [&]() { print(values...); };
     32   byref2();
     33 }
     34 
     35 template void do_print(int, float, double);
     36 
     37 template<typename T, int... Values>
     38 void bogus_expansions(T x) {
     39   auto l1 = [x...] {}; // expected-error{{pack expansion does not contain any unexpanded parameter packs}}
     40   auto l2 = [Values...] {}; // expected-error{{'Values' in capture list does not name a variable}}
     41 }
     42 
     43 void g(int*, float*, double*);
     44 
     45 template<class... Args>
     46 void std_example(Args... args) {
     47   auto lm = [&, args...] { return g(args...); };
     48 };
     49 
     50 template void std_example(int*, float*, double*);
     51 
     52 template<typename ...Args>
     53 void variadic_lambda(Args... args) {
     54   auto lambda = [](Args... inner_args) { return g(inner_args...); };
     55   lambda(args...);
     56 }
     57 
     58 template void variadic_lambda(int*, float*, double*);
     59