llvm-project/clang/test/SemaObjC/call-unavailable-init-in-self.m
Alex Lorenz 194d00e142 [ObjC] Follow-up r350768 and allow the use of unavailable methods that are
declared in a parent class from within the @implementation context

This commit extends r350768 and allows the use of methods marked as unavailable
that are declared in a parent class/category from within the @implementation of
the class where the method is marked as unavailable.
This allows users to call init that's marked as unavailable even if they don't
define it.

rdar://47134898

Differential Revision: https://reviews.llvm.org/D56816

llvm-svn: 351459
2019-01-17 18:12:45 +00:00

87 lines
1.5 KiB
Objective-C

// RUN: %clang_cc1 -x objective-c -verify -fobjc-arc %s
@interface NSObject
+ (instancetype)new;
+ (instancetype)alloc;
- (void)declaredInSuper;
@end
@interface NSObject (Category)
- (void)declaredInSuperCategory;
@end
@interface Sub: NSObject
- (instancetype)init __attribute__((unavailable)); // expected-note 4 {{'init' has been explicitly marked unavailable here}}
- (void)notImplemented __attribute__((unavailable));
- (void)declaredInSuper __attribute__((unavailable));
- (void)declaredInSuperCategory __attribute__((unavailable));
@end
@implementation Sub
+ (Sub *)create {
return [[self alloc] init];
}
+ (Sub *)create2 {
return [self new];
}
+ (Sub *)create3 {
return [Sub new];
}
- (instancetype) init {
return self;
}
- (void)reportUseOfUnimplemented {
[self notImplemented];
}
- (void)allowSuperCallUsingSelf {
[self declaredInSuper];
[[Sub alloc] declaredInSuper];
[self declaredInSuperCategory];
[[Sub alloc] declaredInSuperCategory];
}
@end
@interface SubClassContext: Sub
@end
@implementation SubClassContext
- (void)subClassContext {
(void)[[Sub alloc] init]; // expected-error {{'init' is unavailable}}
(void)[Sub new]; // expected-error {{'new' is unavailable}}
}
@end
void unrelatedContext() {
(void)[[Sub alloc] init]; // expected-error {{'init' is unavailable}}
(void)[Sub new]; // expected-error {{'new' is unavailable}}
}
@interface X @end
@interface X (Foo)
-(void)meth __attribute__((unavailable));
@end
@implementation X (Foo)
-(void)meth {}
-(void)call_it { [self meth]; }
@end