summaryrefslogtreecommitdiff
path: root/test/CXX/temp/temp.decls
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/temp/temp.decls
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/temp/temp.decls')
-rw-r--r--test/CXX/temp/temp.decls/temp.variadic/init-capture.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/test/CXX/temp/temp.decls/temp.variadic/init-capture.cpp b/test/CXX/temp/temp.decls/temp.variadic/init-capture.cpp
new file mode 100644
index 0000000000..4d5b6b4745
--- /dev/null
+++ b/test/CXX/temp/temp.decls/temp.variadic/init-capture.cpp
@@ -0,0 +1,39 @@
+// RUN: %clang_cc1 -std=c++2a -verify %s
+
+namespace p3 {
+ void bar(...);
+ template <typename... Args> void foo(Args... args) {
+ (void)[... xs = args] {
+ bar(xs...);
+ };
+ }
+
+ void use() {
+ foo();
+ foo(1);
+ }
+}
+
+template<typename ...T> void f(T ...t) {
+ (void)[&...x = t] {
+ x; // expected-error {{unexpanded parameter pack 'x'}}
+ };
+
+ // Not OK: can't expand 'x' outside its scope.
+ weird((void)[&...x = t] {
+ return &x; // expected-error {{unexpanded parameter pack 'x'}}
+ }... // expected-error {{does not contain any unexpanded}}
+ );
+
+ // OK, capture only one 'slice' of 'x'.
+ weird((void)[&x = t] {
+ return &x;
+ }...
+ );
+
+ // 'x' is not expanded by the outer '...', but 'T' is.
+ weird((void)[&... x = t] {
+ return T() + &x; // expected-error {{unexpanded parameter pack 'x'}}
+ }... // expected-error {{does not contain any unexpanded}}
+ );
+}