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}} expected-note {{while substituting into a lambda}}
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}} expected-note {{while substituting into a lambda}}
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), const X
*>);
93 static_assert(is_same
<decltype(this), const X
*>);
95 static_assert(is_same
<decltype(this), const X
*>);
101 static_assert(is_same
<decltype(this), const X
*>);
102 auto M
= [this]() mutable {
103 static_assert(is_same
<decltype(this), const X
*>);
105 static_assert(is_same
<decltype(this), const X
*>);
108 auto M2
= [*this]() mutable {
109 static_assert(is_same
<decltype(this), const X
*>);
111 static_assert(is_same
<decltype(this), const X
*>);
116 auto GL1
= [*this](auto a
) {
117 static_assert(is_same
<decltype(this), const X
*>);
118 auto M
= [this](auto b
) mutable {
119 static_assert(is_same
<decltype(this), const X
*>);
120 auto N
= [](auto c
) {
121 static_assert(is_same
<decltype(this), const X
*>);
126 auto M2
= [*this](auto a
) mutable {
127 static_assert(is_same
<decltype(this), const X
*>);
128 auto N
= [](auto b
) {
129 static_assert(is_same
<decltype(this), const X
*>);
133 return [=](auto a
) mutable { M(a
)(a
); M2(a
)(a
); };
139 auto L2
= [this]() mutable {
140 static_assert(is_same
<decltype(this), const X
*>);
141 ++d
; //expected-error{{cannot assign}}
143 auto GL
= [*this](auto a
) mutable {
144 static_assert(is_same
<decltype(this), const X
*>);
145 auto M
= [this](auto b
) {
146 static_assert(is_same
<decltype(this), const X
*>);
147 auto N
= [](auto c
) {
148 static_assert(is_same
<decltype(this), const X
*>);
156 void foo() volatile const {
158 static_assert(is_same
<decltype(this), const volatile X
*>);
159 auto M
= [*this]() mutable {
160 static_assert(is_same
<decltype(this), const volatile X
*>);
162 static_assert(is_same
<decltype(this), const volatile X
*>);
164 static_assert(is_same
<decltype(this), const volatile X
*>);
168 static_assert(is_same
<decltype(this), const volatile X
*>);
171 auto M2
= [*this]() {
172 static_assert(is_same
<decltype(this), const volatile X
*>);
174 static_assert(is_same
<decltype(this), const volatile X
*>);
186 auto L
= [*this]() mutable {
187 auto M
= [=](auto a
) {
189 static_assert(is_same
<decltype(this), const X
*>);
191 static_assert(is_same
<decltype(this), const X
*>);
195 static_assert(is_same
<decltype(this), const X
*>);
217 //OK - the object used to initialize our capture is a const object and so prefers the non-deleted ctor.
218 const auto &&L
= [*this]{};
227 } // namespace test_star_this
230 // https://bugs.llvm.org/show_bug.cgi?id=32831
232 template <typename Func
>
233 void fun_template(Func func
) {
245 auto L
= [this](auto Y
) { member_foo(); };
249 [this](auto) { member_foo(); });
263 (void)[&] { f(this->data
); };
275 auto L
= [this](auto Y
) { member_foo(); };
279 [this](auto) { member_foo(); });
285 return [this] { return [] () -> decltype(data
){ return 0; }; };
288 return [] { return [] () -> decltype(data
){ return 0; }; };
294 } // namespace PR32831
302 auto z
= [*this](auto z2
, decltype(z2(this)) z3
){};
305 } // namespace PR45881
311 void f(S
*) = delete; // expected-note {{would lose const qualifier}}
312 void f(const S
*) = delete; // expected-note {{candidate function has been explicitly deleted}}
316 [*this]() mutable { f(this); }(); // expected-error {{call to deleted function}}