[clang-cl] Ignore /Wv and /Wv:17 flags
[llvm-project.git] / clang / test / SemaCXX / cxx1y-generic-lambdas-variadics.cpp
blobf38fb2c6d71e7680e0372c2b304ca0aa0933e7ca
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
10 namespace explicit_argument_variadics {
13 template<class ... Ts> void print(Ts ... ) { }
15 struct X { };
16 struct Y { };
17 struct Z { };
19 int test() {
21 auto L = [](auto ... as) { };
22 L.operator()<bool>(true);
25 auto L = [](auto a) { };
26 L.operator()<bool>(false);
29 auto L = [](auto a, auto b) { };
30 L.operator()<bool>(false, 'a');
33 auto L = [](auto a, auto b) { };
34 L.operator()<bool, char>(false, 'a');
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");
43 auto L = [](auto ... As) {
45 L.operator()<bool, double>(false, 3.14, "abc");
48 auto L = [](auto A, auto B, auto ... As) {
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}}
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;
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);
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;
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{});
81 return 0;
83 int run = test();
84 } // end ns explicit_argument_extension
88 #ifdef PR18499_FIXED
89 namespace variadic_expansion {
90 void f(int &, char &);
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 }()...);
101 void h(int i, char c) { g(i, c); }
103 #endif
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 (*)(type-parameter-0-0...){{.*}}' against 'int'}}
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 }()...};
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}}
126 void run() {
127 a<1>(); // expected-note {{instantiation of}}
128 b(Pack<int*, float*>(), 1, 2, 3); // expected-note {{instantiation of}}
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}}
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}}