diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2013-04-30 21:23:01 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2013-04-30 21:23:01 +0000 |
commit | 9b1317531d376738fd6631291b0a04109c76a63b (patch) | |
tree | 7ad9189e14f6588a784230d2278ea9399f91c8e3 /lib/Sema/SemaStmt.cpp | |
parent | 3d2f000df9311bfccb6d2ac350be3d3efa5a412b (diff) |
When deducing an 'auto' type, don't modify the type-as-written.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@180808 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaStmt.cpp')
-rw-r--r-- | lib/Sema/SemaStmt.cpp | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp index 63c2a7d8e6..673b84e815 100644 --- a/lib/Sema/SemaStmt.cpp +++ b/lib/Sema/SemaStmt.cpp @@ -1590,25 +1590,22 @@ Sema::ActOnObjCForCollectionStmt(SourceLocation ForLoc, // 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) { + if (DeduceAutoType(D->getTypeSourceInfo(), DeducedInit, FirstType) == + DAR_Failed) DiagnoseAutoDeductionFailure(D, DeducedInit); - } - if (!DeducedType) { + if (FirstType.isNull()) { D->setInvalidDecl(); return StmtError(); } - D->setTypeSourceInfo(DeducedType); - D->setType(DeducedType->getType()); - FirstType = DeducedType->getType(); + D->setType(FirstType); if (ActiveTemplateInstantiations.empty()) { - SourceLocation Loc = DeducedType->getTypeLoc().getBeginLoc(); + SourceLocation Loc = + D->getTypeSourceInfo()->getTypeLoc().getBeginLoc(); Diag(Loc, diag::warn_auto_var_is_id) << D->getDeclName(); } @@ -1645,20 +1642,19 @@ Sema::ActOnObjCForCollectionStmt(SourceLocation ForLoc, /// Finish building a variable declaration for a for-range statement. /// \return true if an error occurs. static bool FinishForRangeVarDecl(Sema &SemaRef, VarDecl *Decl, Expr *Init, - SourceLocation Loc, int diag) { + SourceLocation Loc, int DiagID) { // Deduce the type for the iterator variable now rather than leaving it to // AddInitializerToDecl, so we can produce a more suitable diagnostic. - TypeSourceInfo *InitTSI = 0; + QualType InitType; if ((!isa<InitListExpr>(Init) && Init->getType()->isVoidType()) || - SemaRef.DeduceAutoType(Decl->getTypeSourceInfo(), Init, InitTSI) == + SemaRef.DeduceAutoType(Decl->getTypeSourceInfo(), Init, InitType) == Sema::DAR_Failed) - SemaRef.Diag(Loc, diag) << Init->getType(); - if (!InitTSI) { + SemaRef.Diag(Loc, DiagID) << Init->getType(); + if (InitType.isNull()) { Decl->setInvalidDecl(); return true; } - Decl->setTypeSourceInfo(InitTSI); - Decl->setType(InitTSI->getType()); + Decl->setType(InitType); // In ARC, infer lifetime. // FIXME: ARC may want to turn this into 'const __unsafe_unretained' if |