r351459 - [ObjC] Follow-up r350768 and allow the use of unavailable methods that are
Alex Lorenz via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 17 10:12:45 PST 2019
Author: arphaman
Date: Thu Jan 17 10:12:45 2019
New Revision: 351459
URL: http://llvm.org/viewvc/llvm-project?rev=351459&view=rev
Log:
[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
Modified:
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/test/SemaObjC/call-unavailable-init-in-self.m
cfe/trunk/test/SemaObjC/infer-availability-from-init.m
Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=351459&r1=351458&r2=351459&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Thu Jan 17 10:12:45 2019
@@ -7365,13 +7365,11 @@ ShouldDiagnoseAvailabilityInContext(Sema
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;
}
}
Modified: cfe/trunk/test/SemaObjC/call-unavailable-init-in-self.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/call-unavailable-init-in-self.m?rev=351459&r1=351458&r2=351459&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/call-unavailable-init-in-self.m (original)
+++ cfe/trunk/test/SemaObjC/call-unavailable-init-in-self.m Thu Jan 17 10:12:45 2019
@@ -5,13 +5,24 @@
+ (instancetype)new;
+ (instancetype)alloc;
+- (void)declaredInSuper;
+
+ at end
+
+ at 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
@@ -34,7 +45,14 @@
}
- (void)reportUseOfUnimplemented {
- [self notImplemented]; // expected-error {{'notImplemented' is unavailable}}
+ [self notImplemented];
+}
+
+- (void)allowSuperCallUsingSelf {
+ [self declaredInSuper];
+ [[Sub alloc] declaredInSuper];
+ [self declaredInSuperCategory];
+ [[Sub alloc] declaredInSuperCategory];
}
@end
Modified: cfe/trunk/test/SemaObjC/infer-availability-from-init.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/infer-availability-from-init.m?rev=351459&r1=351458&r2=351459&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/infer-availability-from-init.m (original)
+++ cfe/trunk/test/SemaObjC/infer-availability-from-init.m Thu Jan 17 10:12:45 2019
@@ -47,12 +47,12 @@ void usenotmyobject() {
}
@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
More information about the cfe-commits
mailing list