summaryrefslogtreecommitdiffstats
path: root/clang/test/CXX/temp/temp.decls/temp.variadic/init-capture.cpp
blob: ce2fccc8fe6fb6d7d3c53e157b4619a87d5f1e0a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// 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}}
  );
}

template<int ...a> constexpr auto x = [...z = a] (auto F) { return F(z...); };
static_assert(x<1,2,3>([](int a, int b, int c) { return 100 * a + 10 * b + c; }) == 123);
static_assert(x<1,2,3>([](int a, int b, int c) { return 100 * a + 10 * b + c; }) == 124); // expected-error {{failed}}

template<int ...a> constexpr auto y = [z = a...] (auto F) { return F(z...); }; // expected-error {{must appear before the name of the capture}}
static_assert(y<1,2,3>([](int a, int b, int c) { return 100 * a + 10 * b + c; }) == 123);
static_assert(y<1,2,3>([](int a, int b, int c) { return 100 * a + 10 * b + c; }) == 124); // expected-error {{failed}}
OpenPOWER on IntegriCloud