fix PR3932: [ObjC]Type defined as 'id' is not recognized as a valid object type.

by making ASTContext::isObjCObjectPointerType accept typedefs of id.

llvm-svn: 68931
This commit is contained in:
Chris Lattner 2009-04-12 23:51:02 +00:00
parent 1e2f763c4c
commit bc670459ad
2 changed files with 27 additions and 12 deletions

View File

@ -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;
// If this a pointer to an interface (e.g. NSString*), it is ok.
if (PT->getPointeeType()->isObjCInterfaceType() ||
// If is has NSObject attribute, OK as well.
isObjCNSObjectType(Ty))
return true;
// 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;
// underlying type. Iteratively strip off typedefs so that we can handle
// typedefs of typedefs.
while (TypedefType *TDT = dyn_cast<TypedefType>(Ty)) {
if (Ty.getUnqualifiedType() == getObjCIdType() ||
Ty.getUnqualifiedType() == getObjCClassType())
return true;
Ty = TDT->getDecl()->getUnderlyingType();
}
// If this a pointer to an interface (e.g. NSString*), it is ok.
if (Ty->getAsPointerType()->getPointeeType()->isObjCInterfaceType())
return true;
// If is has NSObject attribute, OK as well.
return isObjCNSObjectType(Ty);
return false;
}
/// getObjCGCAttr - Returns one of GCNone, Weak or Strong objc's

View File

@ -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