Objective-C++ Sema. Fix a bug in instantiation of receivers.

Completes radar 7963410.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@103719 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Fariborz Jahanian 2010-05-13 17:19:25 +00:00
Родитель 6fb745bdf1
Коммит 3ba606199b
3 изменённых файлов: 96 добавлений и 5 удалений

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

@ -977,7 +977,12 @@ Sema::OwningExprResult Sema::BuildInstanceMessage(ExprArg ReceiverE,
CastExpr::CK_IntegralToPointer);
ReceiverType = Receiver->getType();
}
else if (!PerformContextuallyConvertToObjCId(Receiver)) {
else if (getLangOptions().CPlusPlus &&
!PerformContextuallyConvertToObjCId(Receiver)) {
if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Receiver)) {
Receiver = ICE->getSubExpr();
ReceiverType = Receiver->getType();
}
return BuildInstanceMessage(Owned(Receiver),
ReceiverType,
SuperLoc,

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

@ -0,0 +1,87 @@
// RUN: %clang_cc1 -fsyntax-only -verify %s
// rdar: // 7963410
@protocol NSObject @end
@interface NSObject
- (id)init;
- (id) alloc;
- (id) autorelease;
@end
template<class T>
class TNSAutoRef
{
public:
TNSAutoRef(T t)
: fRef(t)
{ }
~TNSAutoRef()
{ }
operator T() const
{ return fRef; }
private:
T fRef;
};
#pragma mark -
@protocol TFooProtocol <NSObject>
- (void) foo;
@end
#pragma mark -
@interface TFoo : NSObject
- (void) setBlah: (id<TFooProtocol>)blah;
@end
#pragma mark -
@implementation TFoo
- (void) setBlah: (id<TFooProtocol>)blah
{ }
@end
#pragma mark -
@interface TBar : NSObject
- (void) setBlah: (id)blah;
@end
#pragma mark -
@implementation TBar
- (void) setBlah: (id)blah
{ }
@end
#pragma mark -
int main (int argc, const char * argv[]) {
NSObject* object1 = [[[NSObject alloc] init] autorelease];
TNSAutoRef<NSObject*> object2([[NSObject alloc] init]);
TNSAutoRef<TBar*> bar([[TBar alloc] init]);
[bar setBlah: object1]; // <== Does not compile. It should.
[bar setBlah: object2]; // <== Does not compile. It should.
return 0;
}

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

@ -28,20 +28,19 @@ private:
@end
@interface TFoo : NSObject
- (void) foo;
@end
@implementation TFoo
- (void) foo
{}
- (void) foo {}
@end
@interface TBar : NSObject
- (void) foo;
@end
@implementation TBar
- (void) foo {}
@end
int main () {