Changeset View
Changeset View
Standalone View
Standalone View
clang/test/SemaObjCXX/instancetype.mm
// RUN: %clang_cc1 -fsyntax-only -verify %s | // RUN: %clang_cc1 -fsyntax-only -verify %s | ||||
#if !__has_feature(objc_instancetype) | #if !__has_feature(objc_instancetype) | ||||
# error Missing 'instancetype' feature macro. | # error Missing 'instancetype' feature macro. | ||||
#endif | #endif | ||||
@interface Root | @interface Root | ||||
+ (instancetype)alloc; | + (instancetype)alloc; // FIXME -- should note {{explicitly declared 'instancetype'}} | ||||
- (instancetype)init; // expected-note{{overridden method is part of the 'init' method family}} | - (instancetype)init; // expected-note{{overridden method is part of the 'init' method family}} | ||||
- (instancetype)self; // expected-note {{explicitly declared 'instancetype'}} | - (instancetype)self; // expected-note {{explicitly declared 'instancetype'}} | ||||
- (Class)class; | - (Class)class; | ||||
@property (assign) Root *selfProp; | @property (assign) Root *selfProp; | ||||
- (instancetype)selfProp; | - (instancetype)selfProp; | ||||
@end | @end | ||||
▲ Show 20 Lines • Show All 121 Lines • ▼ Show 20 Lines | |||||
@optional | @optional | ||||
- (id)methodInProto1; | - (id)methodInProto1; | ||||
- (Subclass1 *)methodInProto2; | - (Subclass1 *)methodInProto2; | ||||
- (int)otherMethodInProto2; // expected-warning{{protocol method is expected to return an instance of the implementing class, but is declared to return 'int'}} | - (int)otherMethodInProto2; // expected-warning{{protocol method is expected to return an instance of the implementing class, but is declared to return 'int'}} | ||||
@end | @end | ||||
@implementation Subclass4 | @implementation Subclass4 | ||||
+ (id)alloc { | + (id)alloc { | ||||
return self; // FIXME: we accept this in ObjC++ but not ObjC? | return self; // FIXME -- should error{{cannot initialize return object of type 'Subclass4 *' with an lvalue of type 'Class'}} | ||||
} | } | ||||
- (Subclass3 *)init { return 0; } // don't complain: we lost the related return type | - (Subclass3 *)init { return 0; } // don't complain: we lost the related return type | ||||
- (Subclass3 *)self { return 0; } // expected-warning{{method is expected to return an instance of its class type 'Subclass4', but is declared to return 'Subclass3 *'}} | - (Subclass3 *)self { return 0; } // expected-warning{{method is expected to return an instance of its class type 'Subclass4', but is declared to return 'Subclass3 *'}} | ||||
- (Subclass4 *)initOther { return 0; } | - (Subclass4 *)initOther { return 0; } | ||||
▲ Show 20 Lines • Show All 69 Lines • Show Last 20 Lines |