llvm-project/clang/lib/Serialization
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
..
ASTCommon.cpp [OPENMP 4.0] Initial support for 'omp declare reduction' construct. 2016-03-03 05:21:39 +00:00
ASTCommon.h Only instantiate a default argument once. 2016-01-06 22:34:54 +00:00
ASTReader.cpp Serialize `pragma pointers_to_members` state. 2016-03-03 00:17:35 +00:00
ASTReaderDecl.cpp [Cxx1z] Implement Lambda Capture of *this by Value as [=,*this] (P0018R3) 2016-03-21 09:25:37 +00:00
ASTReaderInternals.h Re-commit r246497 (and dependent changes r246524 and r246521), reverted in 2015-09-01 20:35:42 +00:00
ASTReaderStmt.cpp P0184R0: Allow types of 'begin' and 'end' expressions in range-based for loops to differ. 2016-03-20 10:33:40 +00:00
ASTWriter.cpp [Cxx1z] Implement Lambda Capture of *this by Value as [=,*this] (P0018R3) 2016-03-21 09:25:37 +00:00
ASTWriterDecl.cpp [OPENMP 4.0] Codegen for 'declare reduction' construct. 2016-03-04 09:22:22 +00:00
ASTWriterStmt.cpp P0184R0: Allow types of 'begin' and 'end' expressions in range-based for loops to differ. 2016-03-20 10:33:40 +00:00
CMakeLists.txt Introduce module file extensions to piggy-back data onto module files. 2015-11-03 18:33:07 +00:00
GeneratePCH.cpp Introduce module file extensions to piggy-back data onto module files. 2015-11-03 18:33:07 +00:00
GlobalModuleIndex.cpp Annotate dump() methods with LLVM_DUMP_METHOD, addressing Richard Smith r259192 post commit comment. 2016-01-29 19:38:18 +00:00
Module.cpp Annotate dump() methods with LLVM_DUMP_METHOD, addressing Richard Smith r259192 post commit comment. 2016-01-29 19:38:18 +00:00
ModuleFileExtension.cpp Introduce module file extensions to piggy-back data onto module files. 2015-11-03 18:33:07 +00:00
ModuleManager.cpp Fix use-after-free in ModuleManager 2015-10-21 23:12:45 +00:00
MultiOnDiskHashTable.h Roll-back r250822. 2015-10-20 13:23:58 +00:00