diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2011-07-26 17:58:54 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2011-07-26 17:58:54 +0000 |
commit | 8eaefdc6aed76e26619caffed030a57438280897 (patch) | |
tree | 17d1635683348a52233cd3af87298c587f011277 | |
parent | a0651c5f5d1c8928d3ae062435ed9cf0aa0d04ba (diff) |
Provide fixit for static use of objective-c type
in few more places and in each instance, fix up
the type to the expected type. // rdar://9603056
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@136103 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 31 | ||||
-rw-r--r-- | test/FixIt/fixit-static-object-decl.m | 11 |
2 files changed, 33 insertions, 9 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index d231d3ccab..cb82b0c489 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -3939,7 +3939,8 @@ void Sema::CheckVariableDeclaration(VarDecl *NewVD, if (T->isObjCObjectType()) { Diag(NewVD->getLocation(), diag::err_statically_allocated_object) << FixItHint::CreateInsertion(NewVD->getLocation(), "*"); - return NewVD->setInvalidDecl(); + T = Context.getObjCObjectPointerType(T); + NewVD->setType(T); } // Emit an error if an address space was applied to decl with local storage. @@ -4179,8 +4180,18 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC, if (R->getAs<FunctionType>()->getResultType()->isObjCObjectType()) { Diag(D.getIdentifierLoc(), diag::err_object_cannot_be_passed_returned_by_value) << 0 - << R->getAs<FunctionType>()->getResultType(); - D.setInvalidType(); + << R->getAs<FunctionType>()->getResultType() + << FixItHint::CreateInsertion(D.getIdentifierLoc(), "*"); + + QualType T = R->getAs<FunctionType>()->getResultType(); + T = Context.getObjCObjectPointerType(T); + if (const FunctionProtoType *FPT = dyn_cast<FunctionProtoType>(R)) { + FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo(); + R = Context.getFunctionType(T, FPT->arg_type_begin(), + FPT->getNumArgs(), EPI); + } + else if (isa<FunctionNoProtoType>(R)) + R = Context.getFunctionNoProtoType(T); } FunctionDecl *NewFD; @@ -6195,8 +6206,10 @@ ParmVarDecl *Sema::CheckParameter(DeclContext *DC, SourceLocation StartLoc, // passed by reference. if (T->isObjCObjectType()) { Diag(NameLoc, - diag::err_object_cannot_be_passed_returned_by_value) << 1 << T; - New->setInvalidDecl(); + diag::err_object_cannot_be_passed_returned_by_value) << 1 << T + << FixItHint::CreateInsertion(NameLoc, "*"); + T = Context.getObjCObjectPointerType(T); + New->setType(T); } // ISO/IEC TR 18037 S6.7.3: "The type of an object with automatic storage @@ -8403,10 +8416,10 @@ void Sema::ActOnFields(Scope* S, Record->setHasObjectMember(true); } else if (FDTy->isObjCObjectType()) { /// A field cannot be an Objective-c object - Diag(FD->getLocation(), diag::err_statically_allocated_object); - FD->setInvalidDecl(); - EnclosingDecl->setInvalidDecl(); - continue; + Diag(FD->getLocation(), diag::err_statically_allocated_object) + << FixItHint::CreateInsertion(FD->getLocation(), "*"); + QualType T = Context.getObjCObjectPointerType(FD->getType()); + FD->setType(T); } else if (!getLangOptions().CPlusPlus) { if (getLangOptions().ObjCAutoRefCount && Record && !ARCErrReported) { diff --git a/test/FixIt/fixit-static-object-decl.m b/test/FixIt/fixit-static-object-decl.m index c9661e275e..65437dbfeb 100644 --- a/test/FixIt/fixit-static-object-decl.m +++ b/test/FixIt/fixit-static-object-decl.m @@ -9,10 +9,21 @@ // RUN: %clang_cc1 -fsyntax-only -Werror -x objective-c++ %t // rdar://9603056 +@interface S @end + @interface NSArray +{ +@public + S iS; +} + (id) arrayWithObjects; @end +NSArray func() { + NSArray P; + return P; +} + int main() { NSArray pluginNames = [NSArray arrayWithObjects]; } |