1 // RUN: %clang_cc1 -std=c++1y -verify -fsyntax-only -fblocks %s
2 // RUN: %clang_cc1 -std=c++1y -verify -fsyntax-only -fblocks -fdelayed-template-parsing %s -DDELAYED_TEMPLATE_PARSING
3 // RUN: %clang_cc1 -std=c++1y -verify -fsyntax-only -fblocks -fms-extensions %s -DMS_EXTENSIONS
4 // RUN: %clang_cc1 -std=c++1y -verify -fsyntax-only -fblocks -fdelayed-template-parsing -fms-extensions %s -DMS_EXTENSIONS -DDELAYED_TEMPLATE_PARSING
5 // RUN: %clang_cc1 -std=c++1y -verify -fsyntax-only -fblocks -triple i386-windows %s
6 // RUN: %clang_cc1 -std=c++1y -verify -fsyntax-only -fblocks -triple i386-windows -fdelayed-template-parsing %s -DDELAYED_TEMPLATE_PARSING
7 // RUN: %clang_cc1 -std=c++1y -verify -fsyntax-only -fblocks -triple i386-windows -fms-extensions %s -DMS_EXTENSIONS
8 // RUN: %clang_cc1 -std=c++1y -verify -fsyntax-only -fblocks -triple i386-windows -fdelayed-template-parsing -fms-extensions %s -DMS_EXTENSIONS -DDELAYED_TEMPLATE_PARSING
9 
10 namespace explicit_argument_variadics {
11 
12 
print(Ts...)13 template<class ... Ts> void print(Ts ... ) { }
14 
15 struct X { };
16 struct Y { };
17 struct Z { };
18 
test()19 int test() {
20   {
21     auto L = [](auto ... as) { };
22     L.operator()<bool>(true);
23   }
24   {
25     auto L = [](auto a) { };
26     L.operator()<bool>(false);
27   }
28   {
29     auto L = [](auto a, auto b) { };
30     L.operator()<bool>(false, 'a');
31   }
32   {
33     auto L = [](auto a, auto b) { };
34     L.operator()<bool, char>(false, 'a');
35   }
36   {
37     auto L = [](auto a, auto b, auto ... cs) { };
38     L.operator()<bool, char>(false, 'a');
39     L.operator()<bool, char, const char*>(false, 'a', "jim");
40   }
41 
42   {
43     auto L = [](auto ... As) {
44     };
45     L.operator()<bool, double>(false, 3.14, "abc");
46   }
47   {
48     auto L = [](auto A, auto B, auto ... As) {
49     };
50     L.operator()<bool>(false, 3.14, "abc");
51     L.operator()<bool, char>(false, 3.14, "abc"); //expected-warning{{implicit conversion}}
52     L.operator()<X, Y, bool, Z>(X{}, Y{}, 3.14, Z{}, X{}); //expected-warning{{implicit conversion}}
53   }
54   {
55     auto L = [](auto ... As) {
56       print("\nL::As = ", As ...);
57       return [](decltype(As) ... as, auto ... Bs) {
58         print("\nL::Inner::as = ", as ...);
59         print("\nL::Inner::Bs = ", Bs ...);
60         return 4;
61       };
62     };
63     auto M = L.operator()<bool, double>(false, 3.14, "abc");
64     M(false, 6.26, "jim", true);
65     M.operator()<bool>(true, 6.26, "jim", false, 3.14);
66   }
67   {
68     auto L = [](auto A, auto ... As) {
69       print("\nL::As = ", As ...);
70       return [](decltype(As) ... as, decltype(A) a, auto ... Bs) {
71         print("\nL::Inner::as = ", as ...);
72         print("\nL::Inner::Bs = ", Bs ...);
73         return 4;
74       };
75     };
76     auto M = L.operator()<bool, double>(false, 3.14, "abc");
77     M(6.26, "jim", true);
78     M.operator()<X>(6.26, "jim", false, X{}, Y{}, Z{});
79   }
80 
81   return 0;
82 }
83  int run = test();
84 } // end ns explicit_argument_extension
85 
86 
87 
88 #ifdef PR18499_FIXED
89 namespace variadic_expansion {
90   void f(int &, char &);
91 
g(T &...t)92   template <typename ... T> void g(T &... t) {
93     f([&a(t)]()->decltype(auto) {
94       return a;
95     }() ...);
96     f([&a(f([&b(t)]()->decltype(auto) { return b; }()...), t)]()->decltype(auto) {
97       return a;
98     }()...);
99   }
100 
h(int i,char c)101   void h(int i, char c) { g(i, c); }
102 }
103 #endif
104 
105 namespace PR33082 {
a()106   template<int ...I> void a() {
107     int arr[] = { [](auto ...K) { (void)I; } ... }; // expected-error {{no viable conversion}} expected-note {{candidate}}
108   }
109 
110   template<typename ...T> struct Pack {};
b(Pack<U...>,T...t)111   template<typename ...T, typename ...U> void b(Pack<U...>, T ...t) {
112     int arr[] = {[t...]() { // expected-error 2{{cannot initialize an array element of type 'int' with}}
113       U u;
114       return u;
115     }()...};
116   }
117 
c()118   void c() {
119     int arr[] = {[](auto... v) {
120       v; // expected-error {{unexpanded parameter pack 'v'}}
121     }...}; // expected-error {{pack expansion does not contain any unexpanded parameter packs}}
122   }
123 
run()124   void run() {
125     a<1>(); // expected-note {{instantiation of}}
126     b(Pack<int*, float*>(), 1, 2, 3); // expected-note {{instantiation of}}
127   }
128 }
129 
pr42587()130 void pr42587() {
131   (void)[](auto... args) -> decltype(args) {}; // expected-error {{type contains unexpanded parameter pack}}
132   (void)[](auto... args, int = args) {}; // expected-error {{default argument contains unexpanded parameter pack}}
133   (void)[](auto... args, decltype(args)) {}; // expected-error {{type contains unexpanded parameter pack}}
134   (void)[](auto... args, decltype(args)...) {}; // (ok)
135   (void)[](auto... args, int = [=] { return args; }()) {}; // expected-error {{default argument contains unexpanded parameter pack}}
136   (void)([]<typename ...T> (T t) {} + ...); // expected-error {{contains unexpanded parameter pack 'T'}} expected-error {{does not contain any unexpanded}} expected-warning 0-2{{extension}}
137   (void)([]<int ...N> (int k = N) {} + ...); // expected-error {{contains unexpanded parameter pack 'N'}} expected-error {{does not contain any unexpanded}} expected-warning 0-2{{extension}}
138   (void)([]<template<typename> typename ...T> (T<int>) {} + ...); // expected-error {{contains unexpanded parameter pack 'T'}} expected-error {{does not contain any unexpanded}} expected-warning 0-3{{extension}}
139 }
140 
__anon4f5e1f0e1402null141 template<typename ...T> int v = {[...x = T()] { int k = x; } ...}; // expected-error {{contains unexpanded parameter pack 'x'}} expected-error {{does not contain any unexpanded}} expected-warning 0-1{{extension}}
142