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.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@103672 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Fariborz Jahanian 2010-05-12 23:29:11 +00:00
Родитель edd8df9cd2
Коммит 79d3f04688
4 изменённых файлов: 85 добавлений и 0 удалений

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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