summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorEli Friedman <eli.friedman@gmail.com>2012-02-03 23:06:43 +0000
committerEli Friedman <eli.friedman@gmail.com>2012-02-03 23:06:43 +0000
commita023e0c619b340e91ff6c9a53e6945e3ae23dccd (patch)
tree8e41a0d5a3b8613dd0012211e612013d2b29413d /clang/lib
parent24af85047046f23f1f4cb18a7bdf7240490b921e (diff)
downloadbcm5719-llvm-a023e0c619b340e91ff6c9a53e6945e3ae23dccd.tar.gz
bcm5719-llvm-a023e0c619b340e91ff6c9a53e6945e3ae23dccd.zip
Make explicit captures which cause implicit captures work correctly.
llvm-svn: 149719
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Sema/SemaExpr.cpp10
-rw-r--r--clang/lib/Sema/SemaExprCXX.cpp17
2 files changed, 12 insertions, 15 deletions
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 8e196fbfe21..8c49c537c5f 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -9453,7 +9453,8 @@ static bool shouldAddConstForScope(CapturingScopeInfo *CSI, VarDecl *VD) {
// Check if the variable needs to be captured; if so, try to perform
// the capture.
// FIXME: Add support for explicit captures.
-void Sema::TryCaptureVar(VarDecl *var, SourceLocation loc) {
+void Sema::TryCaptureVar(VarDecl *var, SourceLocation loc,
+ TryCaptureKind Kind) {
DeclContext *DC = CurContext;
if (var->getDeclContext() == DC) return;
if (!var->hasLocalStorage()) return;
@@ -9536,7 +9537,12 @@ void Sema::TryCaptureVar(VarDecl *var, SourceLocation loc) {
}
bool byRef;
- if (CSI->ImpCaptureStyle == CapturingScopeInfo::ImpCap_None) {
+ bool isInnermostCapture = (i == e - 1);
+ if (isInnermostCapture && Kind == TryCapture_ExplicitByVal) {
+ byRef = false;
+ } else if (isInnermostCapture && Kind == TryCapture_ExplicitByRef) {
+ byRef = true;
+ } else if (CSI->ImpCaptureStyle == CapturingScopeInfo::ImpCap_None) {
// No capture-default
Diag(loc, diag::err_lambda_impcap) << var->getDeclName();
Diag(var->getLocation(), diag::note_previous_decl) << var->getDeclName();
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 3dd271bb8af..b35ea802e56 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -5030,12 +5030,6 @@ void Sema::ActOnStartOfLambdaDefinition(LambdaIntroducer &Intro,
Diag(Var->getLocation(), diag::note_previous_decl) << C->Id;
continue;
}
-
- if (Var->hasAttr<BlocksAttr>()) {
- Diag(C->Loc, diag::err_lambda_capture_block) << C->Id;
- Diag(Var->getLocation(), diag::note_previous_decl) << C->Id;
- continue;
- }
// C++11 [expr.prim.lambda]p8:
// An identifier or this shall not appear more than once in a
@@ -5046,13 +5040,10 @@ void Sema::ActOnStartOfLambdaDefinition(LambdaIntroducer &Intro,
<< SourceRange(LSI->getCapture(Var).getLocation());
continue;
}
-
- // FIXME: If this is capture by copy, make sure that we can in fact copy
- // the variable.
- // FIXME: Unify with normal capture path, so we get all of the necessary
- // nested captures.
- LSI->AddCapture(Var, /*isBlock*/false, C->Kind == LCK_ByRef,
- /*isNested=*/false, C->Loc, 0);
+
+ TryCaptureKind Kind = C->Kind == LCK_ByRef ? TryCapture_ExplicitByRef :
+ TryCapture_ExplicitByVal;
+ TryCaptureVar(Var, C->Loc, Kind);
}
LSI->finishedExplicitCaptures();
OpenPOWER on IntegriCloud