[cfe-commits] r149977 - in /cfe/trunk: include/clang/AST/ include/clang/Basic/ include/clang/Sema/ lib/AST/ lib/Sema/ lib/Serialization/ lib/StaticAnalyzer/Core/ test/CXX/expr/expr.prim/expr.prim.lambda/ tools/libclang/

Douglas Gregor dgregor at apple.com
Wed Feb 8 11:06:16 PST 2012


On Feb 7, 2012, at 1:16 PM, Eli Friedman wrote:

> On Tue, Feb 7, 2012 at 2:09 AM, Douglas Gregor <dgregor at apple.com> wrote:
>> Author: dgregor
>> Date: Tue Feb  7 04:09:13 2012
>> New Revision: 149977
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=149977&view=rev
>> Log:
>> Introduce basic ASTs for lambda expressions. This covers:
>>  - Capturing variables by-reference and by-copy within a lambda
>>  - The representation of lambda captures
>>  - The creation of the non-static data members in the lambda class
>>  that store the captured variables
>>  - The initialization of the non-static data members from the
>>  captured variables
>>  - Pretty-printing lambda expressions
> 
> [...]
> 
>> +LambdaExpr::LambdaExpr(QualType T,
>> +                       SourceRange IntroducerRange,
>> +                       LambdaCaptureDefault CaptureDefault,
>> +                       ArrayRef<Capture> Captures,
>> +                       bool ExplicitParams,
>> +                       ArrayRef<Expr *> CaptureInits,
>> +                       SourceLocation ClosingBrace)
>> +  : Expr(LambdaExprClass, T, VK_RValue, OK_Ordinary,
>> +         T->isDependentType(), T->isDependentType(), T->isDependentType(),
>> +         /*ContainsUnexpandedParameterPack=*/false),
>> +    IntroducerRange(IntroducerRange),
>> +    NumCaptures(Captures.size()),
>> +    NumExplicitCaptures(0),
>> +    CaptureDefault(CaptureDefault),
>> +    ExplicitParams(ExplicitParams),
>> +    ClosingBrace(ClosingBrace)
>> +{
>> +  assert(CaptureInits.size() == Captures.size() && "Wrong number of arguments");
>> +
>> +  // Copy captures.
>> +  // FIXME: Do we need to update "contains unexpanded parameter pack" here?
> 
> We do if we support expanding lambdas as part of a parameter pack...

That's tricky business, since we'll need to be able to propagate the "contains unexpanded parameter pack" bit all the way through statements and declarations (including declarations of local classes). 

I'll probably clamp down on this first, then we can extend it later.

>> @@ -9654,10 +9720,10 @@
>>       // According to the blocks spec, the capture of a variable from
>>       // the stack requires a const copy constructor.  This is not true
>>       // of the copy/move done to move a __block variable to the heap.
>> -      // There is no equivalent language in the C++11 specification of lambdas.
>> -      if (isBlock)
>> -        type.addConst();
>> +      type.addConst();
>> 
>> +      // FIXME: Add an initialized entity for lambda capture.
>> +      // FIXME: Won't work for arrays, although we do need this behavior.
>>       Expr *declRef = new (Context) DeclRefExpr(var, type, VK_LValue, loc);
>>       ExprResult result =
>>         PerformCopyInitialization(
> 
> Are these two FIXME's relevant?  Lambdas don't use this codepath with
> your patch, and we don't allow capturing arrays in blocks.


No, they aren't relevant any more. Thanks!

  - Doug



More information about the cfe-commits mailing list