Fix 'this' capturing Generic lambdas used within default initializers (PR19876)
authorFaisal Vali <faisalv@yahoo.com>
Fri, 30 May 2014 04:39:37 +0000 (04:39 +0000)
committerFaisal Vali <faisalv@yahoo.com>
Fri, 30 May 2014 04:39:37 +0000 (04:39 +0000)
commit47d9ed4e2005795cb1565a5ec1952cabf777ad62
tree7298bb86270fec4a159fac7a0e263f3a6e25130c
parent5ab77956497f2787c9a8266632ba0e3498630bd6
Fix 'this' capturing Generic lambdas used within default initializers (PR19876)

http://llvm.org/bugs/show_bug.cgi?id=19876

The following C++1y code results in a crash:

struct X {
  int m = 10;
  int n = [this](auto) { return m; }(20);
};

When implicitly instantiating the generic lambda's call operator specialization body, Sema is unable to determine the current 'this' type when transforming the MemberExpr 'm' - since it looks for the nearest enclosing FunctionDeclDC - which is obviously null.

I considered two ways to fix this:

    1) In InstantiateFunctionDefinition, when the context is saved after the lambda scope info is created, retain the 'this' pointer.
    2) Teach getCurrentThisType() to recognize it is within a generic lambda within an NSDMI/default-initializer and return the appropriate this type.

I chose to implement #2 (though I confess I do not have a compelling reason for choosing it over #1).

Richard Smith accepted the patch:
http://reviews.llvm.org/D3935

Thank you!

llvm-svn: 209874
clang/lib/Sema/SemaExprCXX.cpp
clang/test/SemaCXX/cxx1y-generic-lambdas-capturing.cpp