diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2012-03-28 17:56:49 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2012-03-28 17:56:49 +0000 |
commit | ba0afde486f5f6b9d31e970fcf387c021c7bc2ba (patch) | |
tree | 05b6f5651975ba2fca1895f45d55de23ba5169b1 /clang/lib | |
parent | 726bc52a2e5fc9aab54b09db3042f609d7339409 (diff) | |
download | bcm5719-llvm-ba0afde486f5f6b9d31e970fcf387c021c7bc2ba.tar.gz bcm5719-llvm-ba0afde486f5f6b9d31e970fcf387c021c7bc2ba.zip |
objective-c: Improve diagnostics and
provide 'fixit' hint when dictionary index
is not of proper type. // rdar://11062080
llvm-svn: 153584
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 12 | ||||
-rw-r--r-- | clang/lib/Sema/SemaPseudoObject.cpp | 14 |
2 files changed, 16 insertions, 10 deletions
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index ae5257fecbd..6b30643db91 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -3115,19 +3115,19 @@ Sema::CreateBuiltinArraySubscriptExpr(Expr *Base, SourceLocation LLoc, BaseExpr = LHSExp; IndexExpr = RHSExp; ResultType = PTy->getPointeeType(); - } else if (const PointerType *PTy = RHSTy->getAs<PointerType>()) { - // Handle the uncommon case of "123[Ptr]". - BaseExpr = RHSExp; - IndexExpr = LHSExp; - ResultType = PTy->getPointeeType(); } else if (const ObjCObjectPointerType *PTy = - LHSTy->getAs<ObjCObjectPointerType>()) { + LHSTy->getAs<ObjCObjectPointerType>()) { BaseExpr = LHSExp; IndexExpr = RHSExp; Result = BuildObjCSubscriptExpression(RLoc, BaseExpr, IndexExpr, 0, 0); if (!Result.isInvalid()) return Owned(Result.take()); ResultType = PTy->getPointeeType(); + } else if (const PointerType *PTy = RHSTy->getAs<PointerType>()) { + // Handle the uncommon case of "123[Ptr]". + BaseExpr = RHSExp; + IndexExpr = LHSExp; + ResultType = PTy->getPointeeType(); } else if (const ObjCObjectPointerType *PTy = RHSTy->getAs<ObjCObjectPointerType>()) { // Handle the uncommon case of "123[Ptr]". diff --git a/clang/lib/Sema/SemaPseudoObject.cpp b/clang/lib/Sema/SemaPseudoObject.cpp index effb372303b..aebc0eb6084 100644 --- a/clang/lib/Sema/SemaPseudoObject.cpp +++ b/clang/lib/Sema/SemaPseudoObject.cpp @@ -842,14 +842,20 @@ Sema::ObjCSubscriptKind // If we don't have a class type in C++, there's no way we can get an // expression of integral or enumeration type. const RecordType *RecordTy = T->getAs<RecordType>(); - if (!RecordTy) + if (!RecordTy && T->isObjCObjectPointerType()) // All other scalar cases are assumed to be dictionary indexing which // caller handles, with diagnostics if needed. return OS_Dictionary; - if (!getLangOpts().CPlusPlus || RecordTy->isIncompleteType()) { + if (!getLangOpts().CPlusPlus || + !RecordTy || RecordTy->isIncompleteType()) { // No indexing can be done. Issue diagnostics and quit. - Diag(FromE->getExprLoc(), diag::err_objc_subscript_type_conversion) - << FromE->getType(); + const Expr *IndexExpr = FromE->IgnoreParenImpCasts(); + if (isa<StringLiteral>(IndexExpr)) + Diag(FromE->getExprLoc(), diag::err_objc_subscript_pointer) + << T << FixItHint::CreateInsertion(FromE->getExprLoc(), "@"); + else + Diag(FromE->getExprLoc(), diag::err_objc_subscript_type_conversion) + << T; return OS_Error; } |