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
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@351459
91177308-0d34-0410-b5e6-
96231b3b80d8
return true;
} else if (K == AR_Unavailable) {
// It is perfectly fine to refer to an 'unavailable' Objective-C method
- // when it's actually defined and is referenced from within the
- // @implementation itself. In this context, we interpret unavailable as a
- // form of access control.
+ // when it is referenced from within the @implementation itself. In this
+ // context, we interpret unavailable as a form of access control.
if (const auto *MD = dyn_cast<ObjCMethodDecl>(OffendingDecl)) {
if (const auto *Impl = dyn_cast<ObjCImplDecl>(C)) {
- if (MD->getClassInterface() == Impl->getClassInterface() &&
- MD->isDefined())
+ if (MD->getClassInterface() == Impl->getClassInterface())
return true;
}
}
+ (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)); // expected-note {{'notImplemented' has been explicitly marked unavailable here}}
+- (void)notImplemented __attribute__((unavailable));
+
+- (void)declaredInSuper __attribute__((unavailable));
+- (void)declaredInSuperCategory __attribute__((unavailable));
@end
}
- (void)reportUseOfUnimplemented {
- [self notImplemented]; // expected-error {{'notImplemented' is unavailable}}
+ [self notImplemented];
+}
+
+- (void)allowSuperCallUsingSelf {
+ [self declaredInSuper];
+ [[Sub alloc] declaredInSuper];
+ [self declaredInSuperCategory];
+ [[Sub alloc] declaredInSuperCategory];
}
@end
}
@interface FromSelf : NSObject
--(instancetype)init __attribute__((unavailable)); // expected-note {{'init' has been explicitly marked unavailable here}}
+-(instancetype)init __attribute__((unavailable));
+(FromSelf*)another_one;
@end
@implementation FromSelf
+(FromSelf*)another_one {
- [self new]; // expected-error{{'new' is unavailable}}
+ [self new];
}
@end