diff options
author | Douglas Gregor <dgregor@apple.com> | 2013-03-07 22:57:58 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2013-03-07 22:57:58 +0000 |
commit | 1344e94cdf51cabb09d7b598323e54bbf333fcd5 (patch) | |
tree | c2fa26dad33e42b85fc2bd06f42002d80a7b290b /lib/Sema/SemaDecl.cpp | |
parent | 6cda3e604f2a2fa289cc9145719ba84461315e21 (diff) |
Improve LLDB's implicit cast-to-id to work with C++11 auto and any Objective-C object type <rdar://problem/13338107>.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176665 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaDecl.cpp')
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 4fa790515d..00d1cf157b 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -7125,6 +7125,20 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init, DeduceInit = CXXDirectInit->getExpr(0); } } + + // Expressions default to 'id' when we're in a debugger. + bool DefaultedToAuto = false; + if (getLangOpts().DebuggerCastResultToId && + Init->getType() == Context.UnknownAnyTy) { + ExprResult Result = forceUnknownAnyToType(Init, Context.getObjCIdType()); + if (Result.isInvalid()) { + VDecl->setInvalidDecl(); + return; + } + Init = Result.take(); + DefaultedToAuto = true; + } + TypeSourceInfo *DeducedType = 0; if (DeduceAutoType(VDecl->getTypeSourceInfo(), DeduceInit, DeducedType) == DAR_Failed) @@ -7145,7 +7159,7 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init, // 'id' instead of a specific object type prevents most of our usual checks. // We only want to warn outside of template instantiations, though: // inside a template, the 'id' could have come from a parameter. - if (ActiveTemplateInstantiations.empty() && + if (ActiveTemplateInstantiations.empty() && !DefaultedToAuto && DeducedType->getType()->isObjCIdType()) { SourceLocation Loc = DeducedType->getTypeLoc().getBeginLoc(); Diag(Loc, diag::warn_auto_var_is_id) @@ -7236,17 +7250,17 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init, // CheckInitializerTypes may change it. QualType DclT = VDecl->getType(), SavT = DclT; - // Top-level message sends default to 'id' when we're in a debugger - // and we are assigning it to a variable of 'id' type. - if (getLangOpts().DebuggerCastResultToId && DclT->isObjCIdType()) - if (Init->getType() == Context.UnknownAnyTy && isa<ObjCMessageExpr>(Init)) { - ExprResult Result = forceUnknownAnyToType(Init, Context.getObjCIdType()); - if (Result.isInvalid()) { - VDecl->setInvalidDecl(); - return; - } - Init = Result.take(); + // Expressions default to 'id' when we're in a debugger + // and we are assigning it to a variable of Objective-C pointer type. + if (getLangOpts().DebuggerCastResultToId && DclT->isObjCObjectPointerType() && + Init->getType() == Context.UnknownAnyTy) { + ExprResult Result = forceUnknownAnyToType(Init, Context.getObjCIdType()); + if (Result.isInvalid()) { + VDecl->setInvalidDecl(); + return; } + Init = Result.take(); + } // Perform the initialization. if (!VDecl->isInvalidDecl()) { |