]> granicus.if.org Git - clang/commitdiff
Only add 'const' to the type of variables captured in a lambda when
authorDouglas Gregor <dgregor@apple.com>
Fri, 17 Feb 2012 04:02:59 +0000 (04:02 +0000)
committerDouglas Gregor <dgregor@apple.com>
Fri, 17 Feb 2012 04:02:59 +0000 (04:02 +0000)
we're capturing it by value in a non-mutable lambda.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150791 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExpr.cpp
test/CXX/expr/expr.prim/expr.prim.lambda/p18.cpp

index 5202f96354d81e4aaa24069027aaccf4d02dbf6e..c15102c4da2f53ca60712953d82f4c9a8639c5dd 100644 (file)
@@ -9575,8 +9575,13 @@ static bool shouldAddConstForScope(CapturingScopeInfo *CSI, VarDecl *VD) {
     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;
 }
 
index 561ead1271e4acc6a748c213c2a9a9ee17852b75..03cbe32ef4e1a8a4a4b66cfd51d1cf2c347a64eb 100644 (file)
@@ -38,4 +38,8 @@ void f3() {
                     "should be const float&");
     }();
   }();
+
+  [&i] {
+    static_assert(is_same<decltype((i)), int&>::value, "should be int&");
+  }();
 }