llvm-project/clang/test/CXX/expr/expr.prim/expr.prim.lambda
Faisal Vali dc6b596ebb [Cxx1z] Implement Lambda Capture of *this by Value as [=,*this] (P0018R3)
Implement lambda capture of *this by copy.
For e.g.:
struct A {

  int d = 10;
  auto foo() { return [*this] (auto a) mutable { d+=a; return d; }; }

};

auto L = A{}.foo(); // A{}'s lifetime is gone.

// Below is still ok, because *this was captured by value.
assert(L(10) == 20);
assert(L(100) == 120);

If the capture was implicit, or [this] (i.e. *this was captured by reference), this code would be otherwise undefined.

Implementation Strategy:
  - amend the parser to accept *this in the lambda introducer
  - add a new king of capture LCK_StarThis
  - teach Sema::CheckCXXThisCapture to handle by copy captures of the
    enclosing object (i.e. *this)
  - when CheckCXXThisCapture does capture by copy, the corresponding 
    initializer expression for the closure's data member 
    direct-initializes it thus making a copy of '*this'.
  - in codegen, when assigning to CXXThisValue, if *this was captured by 
    copy, make sure it points to the corresponding field member, and
    not, unlike when captured by reference, what the field member points
    to.
  - mark feature as implemented in svn

Much gratitude to Richard Smith for his carefully illuminating reviews!   

llvm-svn: 263921
2016-03-21 09:25:37 +00:00
..
blocks-irgen.mm More fixes for block mangling. 2013-07-02 17:52:28 +00:00
blocks.mm More fixes for isBetterOverloadCandidate not being a strict weak ordering. The 2014-05-17 04:36:39 +00:00
default-arguments.cpp Instantiate function declarations in instantiated functions. 2015-08-23 10:22:28 +00:00
p2-generic-lambda-1y.cpp Adding a -Wunused-value warning for expressions with side effects used in an unevaluated expression context, such as sizeof(), or decltype(). Also adds a similar warning when the expression passed to typeid() *is* evaluated, since it is equally likely that the user would expect the expression operand to be unevaluated in that case. 2014-12-17 21:57:17 +00:00
p2.cpp PR23334: Perform semantic checking of lambda capture initialization in the right context. 2015-04-27 21:27:54 +00:00
p3.cpp DR1891, PR21787: a lambda closure type has no default constructor, rather than 2014-12-10 20:04:48 +00:00
p4-1y.cpp Implement a rudimentary form of generic lambdas. 2013-09-26 19:54:12 +00:00
p4.cpp DR1048: drop top-level cv-qualifiers when deducing the return type of a 2014-12-19 22:10:51 +00:00
p4.mm
p5-generic-lambda-1y.cpp Normalize line endings 2014-03-02 18:46:05 +00:00
p5.cpp
p6.cpp
p7.cpp
p8.cpp Add compat/extension warnings for init captures. 2013-09-28 05:38:27 +00:00
p10.cpp
p11-1y.cpp N3922: direct-list-initialization of an auto-typed variable no longer deduces a 2015-11-11 01:36:17 +00:00
p11.cpp
p12.cpp
p13.cpp
p14.cpp Require the type of a by-copy capture to be complete before creating its field. 2013-12-18 23:02:36 +00:00
p15-star-this-capture.cpp [Cxx1z] Implement Lambda Capture of *this by Value as [=,*this] (P0018R3) 2016-03-21 09:25:37 +00:00
p15.cpp
p16.cpp Fix typo from r237482. "to reference of type" --> "to reference to type" 2015-05-16 01:39:39 +00:00
p18.cpp
p19.cpp DR1891, PR21787: a lambda closure type has no default constructor, rather than 2014-12-10 20:04:48 +00:00
p20.cpp
p21.cpp
p23.cpp Add compat/extension warnings for init captures. 2013-09-28 05:38:27 +00:00
templates.cpp Clarify the error message when the reason the conversion is not viable is because the returned value does not match the function return type. 2015-08-25 22:18:46 +00:00