aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaExpr.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2012-02-08 20:56:50 +0000
committerDouglas Gregor <dgregor@apple.com>2012-02-08 20:56:50 +0000
commit1e3767ac5449db6a1ede192d5e4217e34fa61f26 (patch)
tree9332829d73de14da542d4117980e904a1a72834c /lib/Sema/SemaExpr.cpp
parent76e3da57b0e8cf72d221f44d54566ef206341668 (diff)
When computing the type of a local variable reference within a lambda,
only add 'const' for variables captured by copy in potentially evaluated expressions of non-mutable lambdas. (The "by copy" part was missing). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150088 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaExpr.cpp')
-rw-r--r--lib/Sema/SemaExpr.cpp12
1 files changed, 11 insertions, 1 deletions
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index bbf992c219..accf85171e 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -2094,6 +2094,15 @@ static bool shouldBuildBlockDeclRef(ValueDecl *D, Sema &S) {
return S.getCurBlock() != 0;
}
+/// \brief Determine whether the given lambda would capture the given
+/// variable by copy.
+static bool willCaptureByCopy(LambdaScopeInfo *LSI, VarDecl *Var) {
+ if (LSI->isCaptured(Var))
+ return LSI->getCapture(Var).isCopyCapture();
+
+ return LSI->ImpCaptureStyle == CapturingScopeInfo::ImpCap_LambdaByval;
+}
+
static bool shouldAddConstQualToVarRef(ValueDecl *D, Sema &S) {
VarDecl *var = dyn_cast<VarDecl>(D);
if (!var)
@@ -2117,7 +2126,8 @@ static bool shouldAddConstQualToVarRef(ValueDecl *D, Sema &S) {
// about decltype hints that it might apply in unevaluated contexts
// as well... and there's precent in our blocks implementation.
return !LSI->Mutable &&
- S.ExprEvalContexts.back().Context != Sema::Unevaluated;
+ S.ExprEvalContexts.back().Context != Sema::Unevaluated &&
+ willCaptureByCopy(LSI, var);
}
static ExprResult BuildBlockDeclRefExpr(Sema &S, ValueDecl *VD,