1 // RUN: %clang_cc1 -std=c++1z -verify -fsyntax-only -fblocks -emit-llvm-only %s
2 // RUN: %clang_cc1 -std=c++1z -verify -fsyntax-only -fblocks -fdelayed-template-parsing %s -DDELAYED_TEMPLATE_PARSING
3 // RUN: %clang_cc1 -std=c++1z -verify -fsyntax-only -fblocks -fms-extensions %s -DMS_EXTENSIONS
4 // RUN: %clang_cc1 -std=c++1z -verify -fsyntax-only -fblocks -fdelayed-template-parsing -fms-extensions %s -DMS_EXTENSIONS -DDELAYED_TEMPLATE_PARSING
6 template <class, class>
7 constexpr bool is_same
= false;
9 constexpr bool is_same
<T
, T
> = true;
11 namespace test_star_this
{
16 (void)[ *this, this ]{}; //expected-error{{'this' can appear only once}}
17 (void)[this] { ++x
; };
18 (void)[*this] { ++x
; }; //expected-error{{read-only variable}}
19 (void)[*this]() mutable { ++x
; };
20 (void)[=] { return x
; };
21 (void)[&, this ] { return x
; };
22 (void)[ =, *this ] { return x
; };
23 (void)[&, *this ] { return x
; };
30 B(const B
&) = delete; //expected-note{{deleted here}}
33 (void)[this] { return x
; };
34 (void)[*this] { return x
; }; //expected-error{{call to deleted}}
41 B(const B
&) = delete; //expected-note2{{deleted here}}
46 template <class T
= int>
48 (void)[this] { return x
; };
49 (void)[*this] { return x
; }; //expected-error2{{call to deleted}}
54 B
*c
= (b
.foo(), nullptr); //expected-note{{in instantiation}}
60 B(const B
&) = delete; //expected-note{{deleted here}}
64 template <class T
= int>
66 const auto &L
= [*this](auto a
) mutable { //expected-error{{call to deleted}}
68 return [this](auto b
) { return d
+= b
; };
76 b
.foo(); //expected-note{{in instantiation}}
84 X(const volatile X
&);
88 void foo() const { //expected-note{{const}}
90 auto L
= [*this]() mutable {
91 static_assert(is_same
<decltype(this), X
*>);
94 static_assert(is_same
<decltype(this), X
*>);
97 static_assert(is_same
<decltype(this), X
*>);
103 static_assert(is_same
<decltype(this), const X
*>);
104 auto M
= [this]() mutable {
105 static_assert(is_same
<decltype(this), const X
*>);
107 static_assert(is_same
<decltype(this), const X
*>);
110 auto M2
= [*this]() mutable {
111 static_assert(is_same
<decltype(this), X
*>);
113 static_assert(is_same
<decltype(this), X
*>);
118 auto GL1
= [*this](auto a
) {
119 static_assert(is_same
<decltype(this), const X
*>);
120 auto M
= [this](auto b
) mutable {
121 static_assert(is_same
<decltype(this), const X
*>);
122 auto N
= [](auto c
) {
123 static_assert(is_same
<decltype(this), const X
*>);
128 auto M2
= [*this](auto a
) mutable {
129 static_assert(is_same
<decltype(this), X
*>);
130 auto N
= [](auto b
) {
131 static_assert(is_same
<decltype(this), X
*>);
135 return [=](auto a
) mutable { M(a
)(a
); M2(a
)(a
); };
141 auto L2
= [this]() mutable {
142 static_assert(is_same
<decltype(this), const X
*>);
143 ++d
; //expected-error{{cannot assign}}
145 auto GL
= [*this](auto a
) mutable {
146 static_assert(is_same
<decltype(this), X
*>);
148 auto M
= [this](auto b
) {
149 static_assert(is_same
<decltype(this), X
*>);
151 auto N
= [](auto c
) {
152 static_assert(is_same
<decltype(this), X
*>);
160 void foo() volatile const {
162 static_assert(is_same
<decltype(this), const volatile X
*>);
163 auto M
= [*this]() mutable {
164 static_assert(is_same
<decltype(this), X
*>);
166 static_assert(is_same
<decltype(this), X
*>);
168 static_assert(is_same
<decltype(this), X
*>);
172 static_assert(is_same
<decltype(this), const X
*>);
175 auto M2
= [*this]() {
176 static_assert(is_same
<decltype(this), const X
*>);
178 static_assert(is_same
<decltype(this), const X
*>);
190 auto L
= [*this]() mutable {
191 auto M
= [=](auto a
) {
194 static_assert(is_same
<decltype(this), X
*>);
196 static_assert(is_same
<decltype(this), const X
*>);
200 static_assert(is_same
<decltype(this), X
*>);
222 //OK - the object used to initialize our capture is a const object and so prefers the non-deleted ctor.
223 const auto &&L
= [*this]{};
232 } // namespace test_star_this
235 // https://bugs.llvm.org/show_bug.cgi?id=32831
237 template <typename Func
>
238 void fun_template(Func func
) {
250 auto L
= [this](auto Y
) { member_foo(); };
254 [this](auto) { member_foo(); });
268 (void)[&] { f(this->data
); };
280 auto L
= [this](auto Y
) { member_foo(); };
284 [this](auto) { member_foo(); });
290 return [this] { return [] () -> decltype(data
){ return 0; }; };
293 return [] { return [] () -> decltype(data
){ return 0; }; };
299 } // namespace PR32831
307 auto z
= [*this](auto z2
, decltype(z2(this)) z3
){};
310 } // namespace PR45881