Add some more implicit conversions for Objective-C++

llvm-svn: 61229
This commit is contained in:
Douglas Gregor 2008-12-18 23:43:31 +00:00
parent 308a1acaaf
commit 1e57a3fb46
2 changed files with 32 additions and 0 deletions

View File

@ -846,6 +846,16 @@ bool Sema::IsPointerConversion(Expr *From, QualType FromType, QualType ToType,
return true;
}
// Objective C++: Allow conversions between the Objective-C "id" and
// "Class", in either direction.
if ((Context.isObjCIdType(FromPointeeType) &&
Context.isObjCClassType(ToPointeeType)) ||
(Context.isObjCClassType(FromPointeeType) &&
Context.isObjCIdType(ToPointeeType))) {
ConvertedType = ToType;
return true;
}
return false;
}
@ -864,6 +874,16 @@ bool Sema::CheckPointerConversion(Expr *From, QualType ToType) {
/*DetectVirtual=*/false);
QualType FromPointeeType = FromPtrType->getPointeeType(),
ToPointeeType = ToPtrType->getPointeeType();
// Objective-C++ conversions are always okay.
// FIXME: We should have a different class of conversions for
// the Objective-C++ implicit conversions.
if (Context.isObjCIdType(FromPointeeType) ||
Context.isObjCIdType(ToPointeeType) ||
Context.isObjCClassType(FromPointeeType) ||
Context.isObjCClassType(ToPointeeType))
return false;
if (FromPointeeType->isRecordType() &&
ToPointeeType->isRecordType()) {
// We must have a derived-to-base conversion. Check an

View File

@ -1,4 +1,16 @@
// RUN: clang -fsyntax-only -verify %s
@interface Foo
@end
@implementation Foo
void func(id);
+ zone {
func(self);
return self;
}
@protocol P0
@end