summaryrefslogtreecommitdiff
path: root/test/CXX/expr/expr.prim
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2019-05-21 20:10:50 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2019-05-21 20:10:50 +0000
commit2cbdb2c8c9b3f69f86778901a4bfbc5a7fb11c79 (patch)
treea9638e027a838edc2442221abe6d38be1e685828 /test/CXX/expr/expr.prim
parent830db7a928404a1f6365312d1045400af3d198b3 (diff)
downloadclang-2cbdb2c8c9b3f69f86778901a4bfbc5a7fb11c79.tar.gz
[c++20] P0780R2: Support pack-expansion of init-captures.
This permits an init-capture to introduce a new pack: template<typename ...T> auto x = [...a = T()] { /* a is a pack */ }; To support this, the mechanism for allowing ParmVarDecls to be packs has been extended to support arbitrary local VarDecls. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@361300 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/CXX/expr/expr.prim')
-rw-r--r--test/CXX/expr/expr.prim/expr.prim.lambda/expr.prim.lambda.capture/p17.cpp42
-rw-r--r--test/CXX/expr/expr.prim/expr.prim.lambda/p23.cpp26
2 files changed, 64 insertions, 4 deletions
diff --git a/test/CXX/expr/expr.prim/expr.prim.lambda/expr.prim.lambda.capture/p17.cpp b/test/CXX/expr/expr.prim/expr.prim.lambda/expr.prim.lambda.capture/p17.cpp
new file mode 100644
index 0000000000..e2bd513aef
--- /dev/null
+++ b/test/CXX/expr/expr.prim/expr.prim.lambda/expr.prim.lambda.capture/p17.cpp
@@ -0,0 +1,42 @@
+// RUN: %clang_cc1 -std=c++2a -verify %s
+
+namespace std_example {
+ namespace std { template<typename T> T &&move(T &); }
+
+ void g(...);
+
+ template <class... Args> void f(Args... args) {
+ auto lm = [&, args...] { return g(args...); };
+ lm();
+
+ auto lm2 = [... xs = std::move(args)] { return g(xs...); };
+ lm2();
+ }
+}
+
+template<typename ...T> constexpr int f(int k, T ...t) {
+ auto a = [...v = t] (bool b) mutable {
+ if (!b) {
+ ((v += 1), ...);
+ return (__SIZE_TYPE__)0;
+ }
+ return (v * ... * 1) + sizeof...(v);
+ };
+ for (int i = 0; i != k; ++i)
+ a(false);
+ return a(true);
+}
+
+static_assert(f(1, 2, 3, 4) == 3 * 4 * 5 + 3);
+static_assert(f(5) == 1);
+
+auto q = [...x = 0] {}; // expected-error {{does not contain any unexpanded parameter packs}}
+
+template<typename ...T> constexpr int nested(T ...t) {
+ return [...a = t] {
+ return [a...] {
+ return (a + ...);
+ }();
+ }();
+}
+static_assert(nested(1, 2, 3) == 6);
diff --git a/test/CXX/expr/expr.prim/expr.prim.lambda/p23.cpp b/test/CXX/expr/expr.prim/expr.prim.lambda/p23.cpp
index 4ae34dec3e..028fcee5fd 100644
--- a/test/CXX/expr/expr.prim/expr.prim.lambda/p23.cpp
+++ b/test/CXX/expr/expr.prim/expr.prim.lambda/p23.cpp
@@ -1,5 +1,6 @@
-// RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify -Wno-c++1y-extensions
-// RUN: %clang_cc1 -fsyntax-only -std=c++1y %s -verify
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify -Wno-c++1y-extensions -Wno-c++2a-extensions
+// RUN: %clang_cc1 -fsyntax-only -std=c++1y %s -verify -Wno-c++2a-extensions
+// RUN: %clang_cc1 -fsyntax-only -std=c++2a %s -verify
void print();
@@ -60,8 +61,25 @@ template void variadic_lambda(int*, float*, double*);
template<typename ...Args>
void init_capture_pack_err(Args ...args) {
- [as(args)...] {} (); // expected-error {{expected ','}}
- [as...(args)]{} (); // expected-error {{expected ','}}
+ [...as(args)]{} ();
+ [as(args)...] {} (); // expected-error {{ellipsis in pack init-capture must appear before the name of the capture}}
+ [as...(args)]{} (); // expected-error {{ellipsis in pack init-capture must appear before the name of the capture}}
+ [...as{args}]{} ();
+ [as{args}...] {} (); // expected-error {{ellipsis in pack init-capture must appear before the name of the capture}}
+ [as...{args}]{} (); // expected-error {{ellipsis in pack init-capture must appear before the name of the capture}}
+ [...as = args]{} ();
+ [as = args...] {} (); // expected-error {{ellipsis in pack init-capture must appear before the name of the capture}}
+ [as... = args]{} (); // expected-error {{ellipsis in pack init-capture must appear before the name of the capture}}
+
+ [&...as(args)]{} ();
+ [...&as(args)]{} (); // expected-error {{ellipsis in pack init-capture must appear before the name of the capture}}
+
+ [args...] {} ();
+ [...args] {} (); // expected-error {{ellipsis in pack capture must appear after the name of the capture}}
+
+ [&args...] {} ();
+ [...&args] {} (); // expected-error {{ellipsis in pack capture must appear after the name of the capture}}
+ [&...args] {} (); // expected-error {{ellipsis in pack capture must appear after the name of the capture}}
}
template<typename ...Args>