aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2013-04-08 18:40:13 +0000
committerDouglas Gregor <dgregor@apple.com>2013-04-08 18:40:13 +0000
commit6f96f4b2b2b24f187f6e8402a260de0c27dd37e9 (patch)
treecb571faff7d8fabe7a64e34ce5489b3e30e5bfd1
parent1cd1f73f09c6ddcf01e3a287d6604cd705190d14 (diff)
<rdar://problem/13540921> Cope with instantiations of the C++11 range-based for loop that end up being Objective-C fast enumeration loops.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@179037 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Sema/TreeTransform.h14
-rw-r--r--test/SemaObjCXX/foreach.mm8
2 files changed, 22 insertions, 0 deletions
diff --git a/lib/Sema/TreeTransform.h b/lib/Sema/TreeTransform.h
index bdd68a7bde..f68de26cde 100644
--- a/lib/Sema/TreeTransform.h
+++ b/lib/Sema/TreeTransform.h
@@ -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);
diff --git a/test/SemaObjCXX/foreach.mm b/test/SemaObjCXX/foreach.mm
index ec6ed0550e..ac787bd09e 100644
--- a/test/SemaObjCXX/foreach.mm
+++ b/test/SemaObjCXX/foreach.mm
@@ -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