Richard Smith | d82201e | 2018-07-07 05:58:48 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -std=c++2a -verify %s -Wdeprecated |
Faisal Vali | 8194a3e | 2017-08-19 03:43:07 +0000 | [diff] [blame] | 2 | |
| 3 | // This test does two things. |
| 4 | // Deleting the copy constructor ensures that an [=, this] capture doesn't copy the object. |
| 5 | // Accessing a member variable from the lambda ensures that the capture actually works. |
| 6 | class A { |
| 7 | A(const A &) = delete; |
| 8 | int i; |
| 9 | |
| 10 | void func() { |
| 11 | auto L = [=, this]() -> int { return i; }; |
| 12 | L(); |
| 13 | } |
| 14 | }; |
Richard Smith | d82201e | 2018-07-07 05:58:48 +0000 | [diff] [blame] | 15 | |
| 16 | struct B { |
| 17 | int i; |
| 18 | void f() { |
| 19 | (void) [=] { // expected-note {{add an explicit capture of 'this'}} |
| 20 | return i; // expected-warning {{implicit capture of 'this' with a capture default of '=' is deprecated}} |
| 21 | }; |
| 22 | } |
| 23 | }; |