[cfe-commits] r150791 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/CXX/expr/expr.prim/expr.prim.lambda/p18.cpp
Douglas Gregor
dgregor at apple.com
Thu Feb 16 20:02:59 PST 2012
Author: dgregor
Date: Thu Feb 16 22:02:59 2012
New Revision: 150791
URL: http://llvm.org/viewvc/llvm-project?rev=150791&view=rev
Log:
Only add 'const' to the type of variables captured in a lambda when
we're capturing it by value in a non-mutable lambda.
Modified:
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p18.cpp
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=150791&r1=150790&r2=150791&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu Feb 16 22:02:59 2012
@@ -9575,8 +9575,13 @@
return false;
if (isa<BlockScopeInfo>(CSI))
return true;
- if (LambdaScopeInfo *LSI = dyn_cast<LambdaScopeInfo>(CSI))
- return !LSI->Mutable;
+ if (LambdaScopeInfo *LSI = dyn_cast<LambdaScopeInfo>(CSI)) {
+ if (LSI->isCaptured(VD))
+ return LSI->getCapture(VD).isCopyCapture() && !LSI->Mutable;
+
+ return LSI->ImpCaptureStyle == LambdaScopeInfo::ImpCap_LambdaByval &&
+ !LSI->Mutable;
+ }
return false;
}
Modified: cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p18.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p18.cpp?rev=150791&r1=150790&r2=150791&view=diff
==============================================================================
--- cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p18.cpp (original)
+++ cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p18.cpp Thu Feb 16 22:02:59 2012
@@ -38,4 +38,8 @@
"should be const float&");
}();
}();
+
+ [&i] {
+ static_assert(is_same<decltype((i)), int&>::value, "should be int&");
+ }();
}
More information about the cfe-commits
mailing list