Debian Codegraph @

clang/test/SemaCXX/lambda-pack-expansion.cpp

raw
1 // RUN: %clang_cc1 -std=c++20 -Wno-unused-value -fsyntax-only -verify %s
2
3 namespace GH49266 {
4 struct X {
5 X() = default;
6 X(X const&) = delete; // expected-note {{'X' has been explicitly marked deleted here}}
7 };
8
9 void take_by_copy(auto &...args) {
10 [...args = args] {}(); // expected-error {{call to deleted constructor}}
11 }
12
13 void take_by_ref(auto &...args) {
14 [&...args = args] {}(); // args is passed by reference and not copied.
15 }
16
17 void foo() {
18 X x;
19 take_by_copy(x); // expected-note {{in instantiation of function template specialization}}
20 take_by_ref(x);
21 }
22 }
23
24 namespace GH48937 {
25
26 template <typename... Ts>
27 consteval int f(Ts... ts) {
28 return ([]<Ts a = 42>(){ return a;}, ...)();
29 }
30
31 static_assert(f(0, 42) == 42);
32
33 template <typename Ts>
34 int g(Ts ts) {
35 return ([]<Ts a = 42>(){ return a;}, ...)(); // expected-error {{pack expansion does not contain any unexpanded parameter packs}}
36 }
37
38 template <typename... Ts>
39 int h(Ts... ts) {
40 return ([]<Ts a = 42>(){ return a;})(); // expected-error {{expression contains unexpanded parameter pack 'Ts'}}
41 }
42
43 }
44
45 namespace GH63677 {
46
47 template<typename>
48 void f() {
49 []<typename... Ts>() -> void {
50 [...us = Ts{}]{
51 (Ts(us), ...);
52 };
53 }.template operator()<int, int>();
54 }
55
56 template void f<int>();
57
58 template <class>
59 inline constexpr auto fun =
60 []<class... Ts>(Ts... ts) {
61 return [... us = (Ts&&) ts]<class Fun>(Fun&& fn) mutable {
62 return static_cast<Fun&&>(fn)(static_cast<Ts&&>(us)...);
63 };
64 };
65
66 void f() {
67 [[maybe_unused]] auto s = fun<int>(1, 2, 3, 4);
68 }
69
70 }
71
72 namespace GH61460 {
73
74 template<typename... Ts>
75 void f1(Ts... ts);
76
77 template <typename... Ts> void g(Ts... p1s) {
78 (void)[&](auto... p2s) {
79 (
80 [&] {
81 p1s;
82 f1(p1s);
83 sizeof(p1s);
84 p2s;
85 },
86 ...);
87 };
88 }
89
90 template <typename... Ts> void g2(Ts... p1s) {
91 (void)[&](auto... p2s) { [&] { p1s; p2s; }; }; // expected-error {{unexpanded parameter pack 'p2s'}}
92 }
93
94 void f1() { g(); }
95
96 } // namespace GH61460
97
98 namespace GH112352 {
99
100 template <class>
101 constexpr bool foo = false;
102
103 template <int>
104 constexpr bool bar = false;
105
106 template <template<class> class>
107 constexpr bool baz = false;
108
109 struct S {
110 template <typename... Types, int... Values> void foldExpr1() {
111 (void)[]<int... Is> {
112 ([] {
113 Is;
114 // Propagate up the flag ContainsUnexpandedParameterPack from VarDecl.
115 S var(foo<Types>);
116 foo<Types>;
117 bar<Values>;
118 int a = Values;
119 } &&
120 ...);
121 };
122 }
123
124 template <template<class> class... TTPs> void foldExpr2() {
125 (void)[]<int... Is> {
126 ([] {
127 Is;
128 baz<TTPs>;
129 TTPs<int> D;
130 } && ...);
131 };
132 }
133 };
134
135 void use() {
136 S().foldExpr1();
137 S().foldExpr2();
138 }
139
140 } // namespace GH112352