[cfe-commits] r150791 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/CXX/expr/expr.prim/expr.prim.lambda/p18.cpp
Eli Friedman
eli.friedman at gmail.com
Thu Feb 16 20:39:03 PST 2012
On Thu, Feb 16, 2012 at 8:02 PM, Douglas Gregor <dgregor at apple.com> wrote:
> 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&");
> + }();
> }
That isn't actually a testcase for your patch; the following is:
struct A { A(); A(A&); };
void a() { A a; [&]{[a]{};}; }
And on a side-note, the following is still broken:
void a() { int a; [=]{ [&] { int&x = a; }; }; }
-Eli
More information about the cfe-commits
mailing list