[cfe-commits] r152573 - in /cfe/trunk: lib/AST/ExprClassification.cpp test/SemaCXX/lambda-expressions.cpp
Eli Friedman
eli.friedman at gmail.com
Mon Mar 12 13:57:19 PDT 2012
Author: efriedma
Date: Mon Mar 12 15:57:19 2012
New Revision: 152573
URL: http://llvm.org/viewvc/llvm-project?rev=152573&view=rev
Log:
Make sure we treat variables captured by reference in lambda as modifiable lvalues. Regression from r152491. Fixes PR12248.
Modified:
cfe/trunk/lib/AST/ExprClassification.cpp
cfe/trunk/test/SemaCXX/lambda-expressions.cpp
Modified: cfe/trunk/lib/AST/ExprClassification.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprClassification.cpp?rev=152573&r1=152572&r2=152573&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprClassification.cpp (original)
+++ cfe/trunk/lib/AST/ExprClassification.cpp Mon Mar 12 15:57:19 2012
@@ -558,18 +558,6 @@
if (Ctx.getLangOpts().CPlusPlus && E->getType()->isFunctionType())
return Cl::CM_Function;
- // You cannot assign to a variable outside a block from within the block if
- // it is not marked __block, e.g.
- // void takeclosure(void (^C)(void));
- // void func() { int x = 1; takeclosure(^{ x = 7; }); }
- if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E)) {
- if (DRE->refersToEnclosingLocal() &&
- isa<VarDecl>(DRE->getDecl()) &&
- cast<VarDecl>(DRE->getDecl())->hasLocalStorage() &&
- !DRE->getDecl()->hasAttr<BlocksAttr>())
- return Cl::CM_NotBlockQualified;
- }
-
// Assignment to a property in ObjC is an implicit setter access. But a
// setter might not exist.
if (const ObjCPropertyRefExpr *Expr = dyn_cast<ObjCPropertyRefExpr>(E)) {
@@ -579,8 +567,19 @@
CanQualType CT = Ctx.getCanonicalType(E->getType());
// Const stuff is obviously not modifiable.
- if (CT.isConstQualified())
+ if (CT.isConstQualified()) {
+ // Special-case variables captured by blocks to get an improved
+ // diagnostic.
+ if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E)) {
+ if (DRE->refersToEnclosingLocal() &&
+ isa<VarDecl>(DRE->getDecl()) &&
+ cast<VarDecl>(DRE->getDecl())->hasLocalStorage() &&
+ !DRE->getDecl()->hasAttr<BlocksAttr>())
+ return Cl::CM_NotBlockQualified;
+ }
return Cl::CM_ConstQualified;
+ }
+
// Arrays are not modifiable, only their elements are.
if (CT->isArrayType())
return Cl::CM_ArrayType;
Modified: cfe/trunk/test/SemaCXX/lambda-expressions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/lambda-expressions.cpp?rev=152573&r1=152572&r2=152573&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/lambda-expressions.cpp (original)
+++ cfe/trunk/test/SemaCXX/lambda-expressions.cpp Mon Mar 12 15:57:19 2012
@@ -133,3 +133,9 @@
} ();
}
}
+
+void PR12248()
+{
+ unsigned int result = 0;
+ auto l = [&]() { ++result; };
+}
More information about the cfe-commits
mailing list