[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
Fri Feb 17 21:56:56 PST 2012
On Feb 16, 2012, at 8:39 PM, Eli Friedman wrote:
> 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]{};}; }
It actually is a test case for my patch, and this…
> And on a side-note, the following is still broken:
>
> void a() { int a; [=]{ [&] { int&x = a; }; }; }
… goes through an entirely different path that was *also* computing the wrong type. I've unified them in r150872.
- Doug
More information about the cfe-commits
mailing list