llvm-project/clang/lib/Parse
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
..
CMakeLists.txt [CMake] Reorder libdeps by alphabetical order. 2014-07-14 04:59:27 +00:00
ParseAST.cpp Restore PrettyStackTrace state on crash. 2015-08-07 17:48:57 +00:00
ParseCXXInlineMethods.cpp Revert "For MS ABI, emit dllexport friend functions defined inline in class" 2016-03-17 20:06:58 +00:00
ParseDecl.cpp Revert r263687 for ubsan bot failure. 2016-03-17 22:13:50 +00:00
ParseDeclCXX.cpp Implement support for [[maybe_unused]] in C++1z that is based off existing support for unused, and treat it as an extension pre-C++1z. This also means extending the existing unused attribute so that it can be placed on an enum and enumerator, in addition to the other subjects. 2016-03-09 16:48:08 +00:00
ParseExpr.cpp Correct typos after acting on invalid subscript expressions 2016-02-19 07:15:33 +00:00
ParseExprCXX.cpp [Cxx1z] Implement Lambda Capture of *this by Value as [=,*this] (P0018R3) 2016-03-21 09:25:37 +00:00
ParseInit.cpp OpaquePtr: Use nullptr construction for ParsedType OpaquePtr typedef 2016-01-15 23:43:34 +00:00
ParseObjc.cpp Fix remaining Clang-tidy readability-redundant-control-flow warnings; other minor fixes. 2016-02-12 22:53:10 +00:00
ParseOpenMP.cpp [OPENMP 4.0] Use 'declare reduction' constructs in 'reduction' clauses. 2016-03-17 10:19:46 +00:00
ParsePragma.cpp Serialize `pragma ms_struct` state. 2016-03-02 23:22:00 +00:00
ParseStmt.cpp [OpenCL] Generate metadata for opencl_unroll_hint attribute 2016-02-19 18:30:11 +00:00
ParseStmtAsm.cpp [ms-inline-asm][AVX512] Add ability to use k registers in MS inline asm + fix bag with curly braces 2016-03-07 18:10:25 +00:00
ParseTemplate.cpp Simplify EnterTokenStream API to make it more robust for memory management 2016-02-09 18:52:09 +00:00
ParseTentative.cpp Add support for GCC's '__auto_type' extension, per the GCC manual: 2015-11-11 02:02:15 +00:00
Parser.cpp Revert r263687 for ubsan bot failure. 2016-03-17 22:13:50 +00:00
RAIIObjectsForParser.h Add a new error for unexpected semi-colon before closing delimiter. 2015-05-12 21:36:35 +00:00