r179037 - <rdar://problem/13540921> Cope with instantiations of the C++11 range-based for loop that end up being Objective-C fast enumeration loops.
Douglas Gregor
dgregor at apple.com
Mon Apr 8 11:40:13 PDT 2013
Author: dgregor
Date: Mon Apr 8 13:40:13 2013
New Revision: 179037
URL: http://llvm.org/viewvc/llvm-project?rev=179037&view=rev
Log:
<rdar://problem/13540921> Cope with instantiations of the C++11 range-based for loop that end up being Objective-C fast enumeration loops.
Modified:
cfe/trunk/lib/Sema/TreeTransform.h
cfe/trunk/test/SemaObjCXX/foreach.mm
Modified: cfe/trunk/lib/Sema/TreeTransform.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TreeTransform.h?rev=179037&r1=179036&r2=179037&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/TreeTransform.h (original)
+++ cfe/trunk/lib/Sema/TreeTransform.h Mon Apr 8 13:40:13 2013
@@ -1338,6 +1338,20 @@ public:
Expr *Cond, Expr *Inc,
Stmt *LoopVar,
SourceLocation RParenLoc) {
+ // If we've just learned that the range is actually an Objective-C
+ // collection, treat this as an Objective-C fast enumeration loop.
+ if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
+ if (RangeStmt->isSingleDecl()) {
+ if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
+ Expr *RangeExpr = RangeVar->getInit();
+ if (!RangeExpr->isTypeDependent() &&
+ RangeExpr->getType()->isObjCObjectPointerType())
+ return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
+ RParenLoc);
+ }
+ }
+ }
+
return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Cond, Inc, LoopVar, RParenLoc,
Sema::BFRK_Rebuild);
Modified: cfe/trunk/test/SemaObjCXX/foreach.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/foreach.mm?rev=179037&r1=179036&r2=179037&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjCXX/foreach.mm (original)
+++ cfe/trunk/test/SemaObjCXX/foreach.mm Mon Apr 8 13:40:13 2013
@@ -16,6 +16,14 @@ void f(NSArray *a) {
for (auto thisKey : keys) { } // expected-warning{{'auto' deduced as 'id' in declaration of 'thisKey'}}
}
+template<typename Collection>
+void ft(Collection col) {
+ for (id x : col) { }
+ for (auto x : col) { }
+}
+
+template void ft(NSArray *);
+
/* // rdar://9072298 */
@protocol NSObject @end
More information about the cfe-commits
mailing list