p23.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify -Wno-c++1y-extensions
  2. // RUN: %clang_cc1 -fsyntax-only -std=c++1y %s -verify
  3. void print();
  4. template<typename T, typename... Ts>
  5. void print(T first, Ts... rest) {
  6. (void)first;
  7. print(rest...);
  8. }
  9. template<typename... Ts>
  10. void unexpanded_capture(Ts ...values) {
  11. auto unexp = [values] {}; // expected-error{{initializer contains unexpanded parameter pack 'values'}}
  12. }
  13. template<typename... Ts>
  14. void implicit_capture(Ts ...values) {
  15. auto implicit = [&] { print(values...); };
  16. implicit();
  17. }
  18. template<typename... Ts>
  19. void do_print(Ts... values) {
  20. auto bycopy = [values...]() { print(values...); };
  21. bycopy();
  22. auto byref = [&values...]() { print(values...); };
  23. byref();
  24. auto bycopy2 = [=]() { print(values...); };
  25. bycopy2();
  26. auto byref2 = [&]() { print(values...); };
  27. byref2();
  28. }
  29. template void do_print(int, float, double);
  30. template<typename T, int... Values>
  31. void bogus_expansions(T x) {
  32. auto l1 = [x...] {}; // expected-error{{pack expansion does not contain any unexpanded parameter packs}}
  33. auto l2 = [Values...] {}; // expected-error{{'Values' in capture list does not name a variable}}
  34. }
  35. void g(int*, float*, double*);
  36. template<class... Args>
  37. void std_example(Args... args) {
  38. auto lm = [&, args...] { return g(args...); };
  39. };
  40. template void std_example(int*, float*, double*);
  41. template<typename ...Args>
  42. void variadic_lambda(Args... args) {
  43. auto lambda = [](Args... inner_args) { return g(inner_args...); };
  44. lambda(args...);
  45. }
  46. template void variadic_lambda(int*, float*, double*);
  47. template<typename ...Args>
  48. void init_capture_pack_err(Args ...args) {
  49. [as(args)...] {} (); // expected-error {{expected ','}}
  50. [as...(args)]{} (); // expected-error {{expected ','}}
  51. }
  52. template<typename ...Args>
  53. void init_capture_pack_multi(Args ...args) {
  54. [as(args...)] {} (); // expected-error {{initializer missing for lambda capture 'as'}} expected-error {{multiple}}
  55. }
  56. template void init_capture_pack_multi(); // expected-note {{instantiation}}
  57. template void init_capture_pack_multi(int);
  58. template void init_capture_pack_multi(int, int); // expected-note {{instantiation}}
  59. template<typename ...Args>
  60. void init_capture_pack_outer(Args ...args) {
  61. print([as(args)] { return sizeof(as); } () ...);
  62. }
  63. template void init_capture_pack_outer();
  64. template void init_capture_pack_outer(int);
  65. template void init_capture_pack_outer(int, int);