[PATCH] D56816: [ObjC] Follow-up r350768 and allow the use of unavailable methods that are declared in a parent class from within the @implementation context
Alex Lorenz via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 17 10:16:43 PST 2019
This revision was automatically updated to reflect the committed changes.
Closed by commit rC351459: [ObjC] Follow-up r350768 and allow the use of unavailable methods that are (authored by arphaman, committed by ).
Changed prior to commit:
https://reviews.llvm.org/D56816?vs=182191&id=182334#toc
Repository:
rC Clang
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D56816/new/
https://reviews.llvm.org/D56816
Files:
lib/Sema/SemaDeclAttr.cpp
test/SemaObjC/call-unavailable-init-in-self.m
test/SemaObjC/infer-availability-from-init.m
Index: test/SemaObjC/infer-availability-from-init.m
===================================================================
--- test/SemaObjC/infer-availability-from-init.m
+++ test/SemaObjC/infer-availability-from-init.m
@@ -47,12 +47,12 @@
}
@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
Index: test/SemaObjC/call-unavailable-init-in-self.m
===================================================================
--- test/SemaObjC/call-unavailable-init-in-self.m
+++ test/SemaObjC/call-unavailable-init-in-self.m
@@ -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
Index: lib/Sema/SemaDeclAttr.cpp
===================================================================
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -7365,13 +7365,11 @@
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;
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D56816.182334.patch
Type: text/x-patch
Size: 2863 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190117/b4ad6a4c/attachment.bin>
More information about the cfe-commits
mailing list