From: Chris Lattner Date: Sun, 12 Apr 2009 23:51:02 +0000 (+0000) Subject: fix PR3932: [ObjC]Type defined as 'id' is not recognized as a valid object type. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=16ede0ec39bf72f5e696e8ed5f1533b29ac2f3d8;p=clang fix PR3932: [ObjC]Type defined as 'id' is not recognized as a valid object type. by making ASTContext::isObjCObjectPointerType accept typedefs of id. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68931 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index ac69a38c3d..f319c3f392 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -2659,22 +2659,29 @@ bool ASTContext::isObjCObjectPointerType(QualType Ty) const { return true; // All other object types are pointers. - if (!Ty->isPointerType()) + const PointerType *PT = Ty->getAsPointerType(); + if (PT == 0) return false; - // Check to see if this is 'id' or 'Class', both of which are typedefs for - // pointer types. This looks for the typedef specifically, not for the - // underlying type. - if (Ty.getUnqualifiedType() == getObjCIdType() || - Ty.getUnqualifiedType() == getObjCClassType()) - return true; - // If this a pointer to an interface (e.g. NSString*), it is ok. - if (Ty->getAsPointerType()->getPointeeType()->isObjCInterfaceType()) + if (PT->getPointeeType()->isObjCInterfaceType() || + // If is has NSObject attribute, OK as well. + isObjCNSObjectType(Ty)) return true; - // If is has NSObject attribute, OK as well. - return isObjCNSObjectType(Ty); + // Check to see if this is 'id' or 'Class', both of which are typedefs for + // pointer types. This looks for the typedef specifically, not for the + // underlying type. Iteratively strip off typedefs so that we can handle + // typedefs of typedefs. + while (TypedefType *TDT = dyn_cast(Ty)) { + if (Ty.getUnqualifiedType() == getObjCIdType() || + Ty.getUnqualifiedType() == getObjCClassType()) + return true; + + Ty = TDT->getDecl()->getUnderlyingType(); + } + + return false; } /// getObjCGCAttr - Returns one of GCNone, Weak or Strong objc's diff --git a/test/SemaObjC/property.m b/test/SemaObjC/property.m index 40bb142d8d..5a119c798c 100644 --- a/test/SemaObjC/property.m +++ b/test/SemaObjC/property.m @@ -39,9 +39,17 @@ @property double bar; @end -int main() { +int func1() { id foo; double bar = [foo bar]; return 0; } +// PR3932 +typedef id BYObjectIdentifier; +@interface Foo1 { + void *isa; +} +@property(copy) BYObjectIdentifier identifier; +@end +