aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaStmt.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2013-04-08 18:25:02 +0000
committerDouglas Gregor <dgregor@apple.com>2013-04-08 18:25:02 +0000
commit1cd1f73f09c6ddcf01e3a287d6604cd705190d14 (patch)
tree5aa0bd2670e4dfbf41b07660989f283d195774f0 /lib/Sema/SemaStmt.cpp
parentf34cb3d3df1612e14a19d259afa3424337cd315e (diff)
<rdar://problem/13540921> Cope with deduced 'auto' in a C++11 for-range loop that is actually an Objective-C fast enumeration loop.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@179035 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaStmt.cpp')
-rw-r--r--lib/Sema/SemaStmt.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp
index ff1db821b6..dea01d5be2 100644
--- a/lib/Sema/SemaStmt.cpp
+++ b/lib/Sema/SemaStmt.cpp
@@ -1570,6 +1570,33 @@ Sema::ActOnObjCForCollectionStmt(SourceLocation ForLoc,
if (!D->hasLocalStorage())
return StmtError(Diag(D->getLocation(),
diag::err_non_variable_decl_in_for));
+
+ // If the type contained 'auto', deduce the 'auto' to 'id'.
+ if (FirstType->getContainedAutoType()) {
+ TypeSourceInfo *DeducedType = 0;
+ OpaqueValueExpr OpaqueId(D->getLocation(), Context.getObjCIdType(),
+ VK_RValue);
+ Expr *DeducedInit = &OpaqueId;
+ if (DeduceAutoType(D->getTypeSourceInfo(), DeducedInit, DeducedType)
+ == DAR_Failed) {
+ DiagnoseAutoDeductionFailure(D, DeducedInit);
+ }
+ if (!DeducedType) {
+ D->setInvalidDecl();
+ return StmtError();
+ }
+
+ D->setTypeSourceInfo(DeducedType);
+ D->setType(DeducedType->getType());
+ FirstType = DeducedType->getType();
+
+ if (ActiveTemplateInstantiations.empty()) {
+ SourceLocation Loc = DeducedType->getTypeLoc().getBeginLoc();
+ Diag(Loc, diag::warn_auto_var_is_id)
+ << D->getDeclName();
+ }
+ }
+
} else {
Expr *FirstE = cast<Expr>(First);
if (!FirstE->isTypeDependent() && !FirstE->isLValue())