llvm-project/clang/lib
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
..
ARCMigrate Fix some Clang-tidy readability-redundant-control-flow warnings; other minor fixes. 2016-02-10 19:11:58 +00:00
AST [Cxx1z] Implement Lambda Capture of *this by Value as [=,*this] (P0018R3) 2016-03-21 09:25:37 +00:00
ASTMatchers Adding new AST matchers for: addrLabelExpr, atomicExpr, binaryConditionalOperator, designatedInitExpr, designatorCountIs, hasSyntacticForm, implicitValueInitExpr, labelDecl, opaqueValueExpr, parenListExpr, predefinedExpr, requiresZeroInitialization, and stmtExpr. 2016-03-09 17:11:51 +00:00
Analysis P0184R0: Allow types of 'begin' and 'end' expressions in range-based for loops to differ. 2016-03-20 10:33:40 +00:00
Basic Reapply [2] [VFS] Add 'overlay-relative' field to YAML files 2016-03-20 02:08:48 +00:00
CodeGen [Cxx1z] Implement Lambda Capture of *this by Value as [=,*this] (P0018R3) 2016-03-21 09:25:37 +00:00
Driver [tsan] Allow -fsanitize=thread for iOS-style simulator targets 2016-03-20 18:24:33 +00:00
Edit Remove autoconf support 2016-01-26 21:30:40 +00:00
Format clang-format: [JS] Make requoting of JavaScript string literals only 2016-03-17 13:03:41 +00:00
Frontend Reapply [2] [VFS] Add 'overlay-relative' field to YAML files 2016-03-20 02:08:48 +00:00
FrontendTool Make it possible for AST plugins to enable themselves by default 2016-03-15 12:51:40 +00:00
Headers Make functions in altivec.h be __inline__. As they are all also marked 2016-03-11 22:13:28 +00:00
Index [index] Make sure that declarations of builtin functions are indexed. 2016-03-17 04:28:19 +00:00
Lex Revert r263687 for ubsan bot failure. 2016-03-17 22:13:50 +00:00
Parse [Cxx1z] Implement Lambda Capture of *this by Value as [=,*this] (P0018R3) 2016-03-21 09:25:37 +00:00
Rewrite Remove use of builtin comma operator. 2016-02-18 22:34:54 +00:00
Sema [Cxx1z] Implement Lambda Capture of *this by Value as [=,*this] (P0018R3) 2016-03-21 09:25:37 +00:00
Serialization [Cxx1z] Implement Lambda Capture of *this by Value as [=,*this] (P0018R3) 2016-03-21 09:25:37 +00:00
StaticAnalyzer [analyzer] Fix missed leak from MSVC specific allocation functions 2016-03-08 01:21:51 +00:00
Tooling Add functions to apply replacements and reformat them. 2016-03-01 12:37:30 +00:00
CMakeLists.txt Fix build with various feature flag combinations 2014-07-14 22:17:22 +00:00