Objective-C++ Sema. Support for conversion of a C++

class object used as a receiver to an objective-c
pointer via a converwsion function. wip.

llvm-svn: 103672
This commit is contained in:
Fariborz Jahanian 2010-05-12 23:29:11 +00:00
parent bf5c83745a
commit cac49a8f8a
4 changed files with 85 additions and 0 deletions

View File

@ -1162,6 +1162,9 @@ public:
ImplicitConversionSequence TryContextuallyConvertToBool(Expr *From);
bool PerformContextuallyConvertToBool(Expr *&From);
ImplicitConversionSequence TryContextuallyConvertToObjCId(Expr *From);
bool PerformContextuallyConvertToObjCId(Expr *&From);
bool PerformObjectMemberConversion(Expr *&From,
NestedNameSpecifier *Qualifier,
NamedDecl *FoundDecl,

View File

@ -976,6 +976,16 @@ Sema::OwningExprResult Sema::BuildInstanceMessage(ExprArg ReceiverE,
ImpCastExprToType(Receiver, Context.getObjCIdType(),
CastExpr::CK_IntegralToPointer);
ReceiverType = Receiver->getType();
}
else if (!PerformContextuallyConvertToObjCId(Receiver)) {
return BuildInstanceMessage(Owned(Receiver),
ReceiverType,
SuperLoc,
Sel,
Method,
LBracLoc,
RBracLoc,
move(ArgsIn));
} else {
// Reject other random receiver types (e.g. structs).
Diag(Loc, diag::err_bad_receiver_type)

View File

@ -2931,6 +2931,27 @@ bool Sema::PerformContextuallyConvertToBool(Expr *&From) {
<< From->getType() << From->getSourceRange();
return true;
}
/// TryContextuallyConvertToObjCId - Attempt to contextually convert the
/// expression From to 'id'.
ImplicitConversionSequence Sema::TryContextuallyConvertToObjCId(Expr *From) {
QualType Ty = Context.getObjCObjectPointerType(Context.ObjCBuiltinIdTy);
return TryImplicitConversion(From, Ty,
// FIXME: Are these flags correct?
/*SuppressUserConversions=*/false,
/*AllowExplicit=*/true,
/*InOverloadResolution=*/false);
}
/// PerformContextuallyConvertToObjCId - Perform a contextual conversion
/// of the expression From to 'id'.
bool Sema::PerformContextuallyConvertToObjCId(Expr *&From) {
QualType Ty = Context.getObjCObjectPointerType(Context.ObjCBuiltinIdTy);
ImplicitConversionSequence ICS = TryContextuallyConvertToObjCId(From);
if (!ICS.isBad())
return PerformImplicitConversion(From, Ty, ICS, AA_Converting);
return true;
}
/// AddOverloadCandidate - Adds the given function to the set of
/// candidate functions, using the given function call arguments. If

View File

@ -0,0 +1,51 @@
// RUN: %clang_cc1 -fsyntax-only -verify %s
// rdar: // 7963410
template<class T>
class TNSAutoRef
{
public:
TNSAutoRef(T t)
: fRef(t)
{ }
~TNSAutoRef()
{ }
operator T() const
{ return fRef; }
T Get() const
{ return fRef; }
private:
T fRef;
};
@interface NSObject
- (id) alloc;
- (id)init;
@end
@interface TFoo : NSObject
- (void) foo;
@end
@implementation TFoo
- (void) foo
{}
@end
@interface TBar : NSObject
@end
@implementation TBar
@end
int main () {
TNSAutoRef<TBar*> bar([[TBar alloc] init]);
[bar foo];
return 0;
}