See 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);
};
This is because when implicitly instantiating the generic lambda's call operator specialization body, Sema gets confused and is unable to determine the current 'this' type when transforming the MemberExpr 'm'.
That is SemaExprCXX.cpp:Sema::getCurrentThisType() is unable to calculate that the this type should be X* since it looks for the nearest enclosing FunctionDeclDC - which is obviously null.
I suppose there are two ways to fix this:
- In InstantiateFunctionDefinition, when the context is saved after the lambda scope info is created, retain the 'this' pointer.
- Teach getCurrentThisType() to recognize it is within a generic lambda within an NSDMI and return the appropriate this type.
I am not sure which way is definitely better - but either one seemed easy to implement.
I chose #2 - although I can't think of a good reason for choosing it over #1.
Feedback will be welcome - and especially if there is another option that might be even more robust.
Thanks!
Instead of these comments, I'd say "There are no cv-qualifiers, per [expr.prim.general]p4." Also, please use "default initializer" rather than "NSDMI".