1 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s -fblocks
3 void test_nest_lambda() {
8 #pragma clang __debug captured
11 y = z; // expected-error{{cannot assign to a variable captured by copy in a non-mutable lambda}}
17 #pragma clang __debug captured
24 c = a; // expected-error{{cannot assign to a variable captured by copy in a non-mutable lambda}}
29 class test_obj_capture {
34 #pragma clang __debug captured
36 #pragma clang __debug captured
41 class test_this_capture {
45 #pragma clang __debug captured
47 #pragma clang __debug captured
49 #pragma clang __debug captured
55 void template_capture_var() {
56 T x; // expected-error{{declaration of reference variable 'x' requires an initializer}}
57 #pragma clang _debug captured
67 void set(const T &v0) {
68 #pragma clang __debug captured
75 void test_capture_var() {
76 template_capture_var<int>(); // OK
77 template_capture_var<int&>(); // expected-note{{in instantiation of function template specialization 'template_capture_var<int &>' requested here}}
83 template <typename S, typename T>
84 S template_capture_var(S x, T y) {
85 #pragma clang _debug captured
88 y++; // expected-error{{read-only variable is not assignable}}
94 // Check if can recover from a template error.
95 void test_capture_var_error() {
96 template_capture_var<int, int>(0, 1); // OK
97 template_capture_var<int, const int>(0, 1); // expected-note{{in instantiation of function template specialization 'template_capture_var<int, const int>' requested here}}
98 template_capture_var<int, int>(0, 1); // OK
101 template <typename T>
102 void template_capture_in_lambda() {
105 #pragma clang __debug captured
113 template_capture_in_lambda<int>(); // OK
118 static void bar() { }
121 template <typename T>
122 void template_capture_func(T &t) {
123 #pragma clang __debug captured
128 #pragma clang __debug captured
134 void test_template_capture_func() {
136 template_capture_func(Obj);
139 template <typename T>
140 T captured_sum(const T &a, const T &b) {
143 #pragma clang __debug captured
151 template <typename T, typename... Args>
152 T captured_sum(const T &a, const Args&... args) {
155 #pragma clang __debug captured
157 result = a + captured_sum(args...);
163 void test_capture_variadic() {
164 (void)captured_sum(1, 2, 3); // OK
165 (void)captured_sum(1, 2, 3, 4, 5); // OK