rdar://18335828
Thanks!
Erik
Paths
| Differential D51189
[Sema][ObjC] Infer availability of +new from availability of -init ClosedPublic Authored by erik.pilkington on Aug 23 2018, 3:27 PM.
Details Summary rdar://18335828 Thanks!
Diff Detail Event TimelineComment Actions Hmm, I don't think this solution is ideal, we'd rather have an attribute somewhere for other consumers of availability annotations. Does MyObject have an implicit decl of new, or are we referring to NSObjects new? Ideally we would an attribute on a particular new instead, but that might not work. Comment Actions
We're referring to NSObject's new. I don't think it's unreasonable to ask users who override init to be unavailable also override new with the same annotation, but it seems like extra boilerplate for something that we can easily infer in clang. What other consumers are you concerned about? Comment Actions
+ @ributzka Comment Actions I feel like this is a much tricky situation than just new and init. Following example is the same situation. __attribute__((objc_root_class)) @interface NSObject - (void) foo; - (void) bar; @end @implementation NSObject - (void) foo {} - (void) bar { [self foo]; } @end @interface MyObject : NSObject - (void) foo __attribute__((unavailable)); @end void test(MyObject *obj) { [obj bar]; } We can do something about [NSObject new] because we know it's implementation but we have to live with more general cases. Comment Actions That's probably the best solution then, I don't think declaring implicit new just for availability attribute is sound. Does this work with self new as well?
erik.pilkington marked 4 inline comments as done. Comment ActionsAddress @arphaman's review comments. Comment Actions
I agree that the general case is impossible to properly diagnose, but I think its totally reasonable for us to special case this pattern with NSObject.
This revision is now accepted and ready to land.Sep 10 2018, 1:49 PM Closed by commit rL341874: [Sema][ObjC] Infer availability of +new from availability of -init. (authored by epilk). · Explain WhySep 10 2018, 3:21 PM This revision was automatically updated to reflect the committed changes.
Revision Contents
Diff 164316 clang/include/clang/AST/ASTContext.h
clang/include/clang/AST/DeclObjC.h
clang/include/clang/AST/NSAPI.h
clang/include/clang/Sema/Sema.h
clang/lib/AST/DeclObjC.cpp
clang/lib/AST/NSAPI.cpp
clang/lib/Sema/SemaDeclAttr.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaExprObjC.cpp
clang/test/SemaObjC/infer-availability-from-init.m
|
const auto