summaryrefslogtreecommitdiffstats
path: root/clang/lib/AST/ExprCXX.cpp
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2013-05-16 06:20:58 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2013-05-16 06:20:58 +0000
commitba71c085234044f8291b82749552a79d01f99631 (patch)
treead88c0f301afad274d85c38231e034b26b8bd300 /clang/lib/AST/ExprCXX.cpp
parentad9971d793e26c6d2ea28353f5b4dc6a2ee19833 (diff)
downloadbcm5719-llvm-ba71c085234044f8291b82749552a79d01f99631.tar.gz
bcm5719-llvm-ba71c085234044f8291b82749552a79d01f99631.zip
First pass of semantic analysis for init-captures: check the initializer, build
a FieldDecl from it, and propagate both into the closure type and the LambdaExpr. You can't do much useful with them yet -- you can't use them within the body of the lambda, because we don't have a representation for "the this of the lambda, not the this of the enclosing context". We also don't have support or a representation for a nested capture of an init-capture yet, which was intended to work despite not being allowed by the current standard wording. llvm-svn: 181985
Diffstat (limited to 'clang/lib/AST/ExprCXX.cpp')
-rw-r--r--clang/lib/AST/ExprCXX.cpp20
1 files changed, 16 insertions, 4 deletions
diff --git a/clang/lib/AST/ExprCXX.cpp b/clang/lib/AST/ExprCXX.cpp
index 402d7b532b2..59e780ae0a1 100644
--- a/clang/lib/AST/ExprCXX.cpp
+++ b/clang/lib/AST/ExprCXX.cpp
@@ -811,7 +811,7 @@ CXXConstructExpr::CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T,
LambdaExpr::Capture::Capture(SourceLocation Loc, bool Implicit,
LambdaCaptureKind Kind, VarDecl *Var,
SourceLocation EllipsisLoc)
- : VarAndBits(Var, 0), Loc(Loc), EllipsisLoc(EllipsisLoc)
+ : DeclAndBits(Var, 0), Loc(Loc), EllipsisLoc(EllipsisLoc)
{
unsigned Bits = 0;
if (Implicit)
@@ -828,15 +828,27 @@ LambdaExpr::Capture::Capture(SourceLocation Loc, bool Implicit,
case LCK_ByRef:
assert(Var && "capture must have a variable!");
break;
+
+ case LCK_Init:
+ llvm_unreachable("don't use this constructor for an init-capture");
}
- VarAndBits.setInt(Bits);
+ DeclAndBits.setInt(Bits);
}
+LambdaExpr::Capture::Capture(FieldDecl *Field)
+ : DeclAndBits(Field,
+ Field->getType()->isReferenceType() ? 0 : Capture_ByCopy),
+ Loc(Field->getLocation()), EllipsisLoc() {}
+
LambdaCaptureKind LambdaExpr::Capture::getCaptureKind() const {
- if (capturesThis())
+ Decl *D = DeclAndBits.getPointer();
+ if (!D)
return LCK_This;
- return (VarAndBits.getInt() & Capture_ByCopy)? LCK_ByCopy : LCK_ByRef;
+ if (isa<FieldDecl>(D))
+ return LCK_Init;
+
+ return (DeclAndBits.getInt() & Capture_ByCopy) ? LCK_ByCopy : LCK_ByRef;
}
LambdaExpr::LambdaExpr(QualType T,
OpenPOWER on IntegriCloud