| 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 |
|
| 13 |
template<class ... Ts> void print(Ts ... ) { } |
| 14 |
|
| 15 |
struct X { }; |
| 16 |
struct Y { }; |
| 17 |
struct Z { }; |
| 18 |
|
| 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 |
|
| 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 |
|
| 101 |
void h(int i, char c) { g(i, c); } |
| 102 |
} |
| 103 |
#endif |
| 104 |
|
| 105 |
namespace PR33082 { |
| 106 |
template<int ...I> void a() { |
| 107 |
int arr[] = { [](auto ...K) { (void)I; } ... }; |
| 108 |
// expected-error@-1 {{no viable conversion}} |
| 109 |
// expected-note-re@-2 {{candidate template ignored: could not match 'auto (*)(auto...){{.*}}' against 'int'}} |
| 110 |
} |
| 111 |
|
| 112 |
template<typename ...T> struct Pack {}; |
| 113 |
template<typename ...T, typename ...U> void b(Pack<U...>, T ...t) { |
| 114 |
int arr[] = {[t...]() { // expected-error 2{{cannot initialize an array element of type 'int' with}} |
| 115 |
U u; |
| 116 |
return u; |
| 117 |
}()...}; |
| 118 |
} |
| 119 |
|
| 120 |
void c() { |
| 121 |
int arr[] = {[](auto... v) { |
| 122 |
v; // expected-error {{unexpanded parameter pack 'v'}} |
| 123 |
}...}; // expected-error {{pack expansion does not contain any unexpanded parameter packs}} |
| 124 |
} |
| 125 |
|
| 126 |
void run() { |
| 127 |
a<1>(); // expected-note {{instantiation of}} |
| 128 |
b(Pack<int*, float*>(), 1, 2, 3); // expected-note {{instantiation of}} |
| 129 |
} |
| 130 |
} |
| 131 |
|
| 132 |
void pr42587() { |
| 133 |
(void)[](auto... args) -> decltype(args) {}; // expected-error {{type contains unexpanded parameter pack}} |
| 134 |
(void)[](auto... args, int = args) {}; // expected-error {{default argument contains unexpanded parameter pack}} |
| 135 |
(void)[](auto... args, decltype(args)) {}; // expected-error {{type contains unexpanded parameter pack}} |
| 136 |
(void)[](auto... args, decltype(args)...) {}; // (ok) |
| 137 |
(void)[](auto... args, int = [=] { return args; }()) {}; // expected-error {{default argument contains unexpanded parameter pack}} |
| 138 |
(void)([]<typename ...T> (T t) {} + ...); // expected-error {{contains unexpanded parameter pack 'T'}} expected-error {{does not contain any unexpanded}} expected-warning 0-2{{extension}} |
| 139 |
(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}} |
| 140 |
(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}} |
| 141 |
} |
| 142 |
|
| 143 |
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}} |