1 // RUN: %clang_cc1 -std=c++1z -verify -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 // RUN: %clang_cc1 -std=c++1z -verify -fblocks -emit-llvm-only %s -fexperimental-new-constant-interpreter
7 // RUN: %clang_cc1 -std=c++1z -verify -fsyntax-only -fblocks -fdelayed-template-parsing %s -DDELAYED_TEMPLATE_PARSING -fexperimental-new-constant-interpreter
8 // RUN: %clang_cc1 -std=c++1z -verify -fsyntax-only -fblocks -fms-extensions %s -DMS_EXTENSIONS -fexperimental-new-constant-interpreter
9 // RUN: %clang_cc1 -std=c++1z -verify -fsyntax-only -fblocks -fdelayed-template-parsing -fms-extensions %s -DMS_EXTENSIONS -DDELAYED_TEMPLATE_PARSING -fexperimental-new-constant-interpreter
11 template <class, class>
12 constexpr bool is_same
= false;
14 constexpr bool is_same
<T
, T
> = true;
16 namespace test_star_this
{
21 (void)[ *this, this ]{}; //expected-error{{'this' can appear only once}}
22 (void)[this] { ++x
; };
23 (void)[*this] { ++x
; }; //expected-error{{read-only variable}}
24 (void)[*this]() mutable { ++x
; };
25 (void)[=] { return x
; };
26 (void)[&, this ] { return x
; };
27 (void)[ =, *this ] { return x
; };
28 (void)[&, *this ] { return x
; };
35 B(const B
&) = delete; //expected-note{{deleted here}}
38 (void)[this] { return x
; };
39 (void)[*this] { return x
; }; //expected-error{{call to deleted}}
46 B(const B
&) = delete; //expected-note2{{deleted here}}
51 template <class T
= int>
53 (void)[this] { return x
; };
54 (void)[*this] { return x
; }; //expected-error2{{call to deleted}}
59 B
*c
= (b
.foo(), nullptr); //expected-note{{in instantiation}}
65 B(const B
&) = delete; //expected-note{{deleted here}}
69 template <class T
= int>
71 const auto &L
= [*this](auto a
) mutable { //expected-error{{call to deleted}}
73 return [this](auto b
) { return d
+= b
; };
81 b
.foo(); //expected-note{{in instantiation}}
89 X(const volatile X
&);
93 void foo() const { //expected-note{{const}}
95 auto L
= [*this]() mutable {
96 static_assert(is_same
<decltype(this), const X
*>);
98 static_assert(is_same
<decltype(this), const X
*>);
100 static_assert(is_same
<decltype(this), const X
*>);
106 static_assert(is_same
<decltype(this), const X
*>);
107 auto M
= [this]() mutable {
108 static_assert(is_same
<decltype(this), const X
*>);
110 static_assert(is_same
<decltype(this), const X
*>);
113 auto M2
= [*this]() mutable {
114 static_assert(is_same
<decltype(this), const X
*>);
116 static_assert(is_same
<decltype(this), const X
*>);
121 auto GL1
= [*this](auto a
) {
122 static_assert(is_same
<decltype(this), const X
*>);
123 auto M
= [this](auto b
) mutable {
124 static_assert(is_same
<decltype(this), const X
*>);
125 auto N
= [](auto c
) {
126 static_assert(is_same
<decltype(this), const X
*>);
131 auto M2
= [*this](auto a
) mutable {
132 static_assert(is_same
<decltype(this), const X
*>);
133 auto N
= [](auto b
) {
134 static_assert(is_same
<decltype(this), const X
*>);
138 return [=](auto a
) mutable { M(a
)(a
); M2(a
)(a
); };
144 auto L2
= [this]() mutable {
145 static_assert(is_same
<decltype(this), const X
*>);
146 ++d
; //expected-error{{cannot assign}}
148 auto GL
= [*this](auto a
) mutable {
149 static_assert(is_same
<decltype(this), const X
*>);
150 auto M
= [this](auto b
) {
151 static_assert(is_same
<decltype(this), const X
*>);
152 auto N
= [](auto c
) {
153 static_assert(is_same
<decltype(this), const X
*>);
161 void foo() volatile const {
163 static_assert(is_same
<decltype(this), const volatile X
*>);
164 auto M
= [*this]() mutable {
165 static_assert(is_same
<decltype(this), const volatile X
*>);
167 static_assert(is_same
<decltype(this), const volatile X
*>);
169 static_assert(is_same
<decltype(this), const volatile X
*>);
173 static_assert(is_same
<decltype(this), const volatile X
*>);
176 auto M2
= [*this]() {
177 static_assert(is_same
<decltype(this), const volatile X
*>);
179 static_assert(is_same
<decltype(this), const volatile X
*>);
191 auto L
= [*this]() mutable {
192 auto M
= [=](auto a
) {
194 static_assert(is_same
<decltype(this), const X
*>);
196 static_assert(is_same
<decltype(this), const X
*>);
200 static_assert(is_same
<decltype(this), const 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
316 void f(S
*) = delete; // expected-note {{would lose const qualifier}}
317 void f(const S
*) = delete; // expected-note {{candidate function has been explicitly deleted}}
321 [*this]() mutable { f(this); }(); // expected-error {{call to deleted function}}