This is an archive of the discontinued LLVM Phabricator instance.

[ObjC] Allow the use of implemented unavailable methods from within the @implementation context
ClosedPublic

Authored by arphaman on Jan 8 2019, 6:08 PM.

Details

Summary

In Objective-C, it's common for some frameworks to mark some methods like init as unavailable in the @interface to prohibit their usage.
However, these frameworks then often implemented said method and refer to it in another method that acts as a factory for that object. The recent change to how messages to self are type checked in clang (r349841) introduced a regression which started to prohibit this pattern with an X is unavailable error. This patch addresses the aforementioned regression.

rdar://47134898

Diff Detail

Repository
rC Clang

Event Timeline

arphaman created this revision.Jan 8 2019, 6:08 PM
thakis added a subscriber: thakis.Jan 8 2019, 6:41 PM

(This would also help with https://crbug.com/917351)

lib/Sema/SemaDeclAttr.cpp
7290

Maybe add a sentence: In this context, we interpret unavailable as a form of access control.

7292

This should be C instead of Ctx right? Sorry, the naming here really sucks.

test/SemaObjC/call-unavailable-init-in-self.m
58

Can you add a test for category implementations:

@interface X @end

@interface X (Foo) 
-(void)meth __attribute__((unavailable))
@end

@implementation X (Foo)
-(void)meth {}
-(void)call_it { [self meth]; }
@end
arphaman marked an inline comment as done.Jan 9 2019, 11:00 AM
arphaman added inline comments.
lib/Sema/SemaDeclAttr.cpp
7292

right, I'll fix that.

arphaman updated this revision to Diff 180901.Jan 9 2019, 12:24 PM
arphaman marked 3 inline comments as done.

Address review comments.

erik.pilkington accepted this revision.Jan 9 2019, 12:29 PM

LGTM, thanks!

This revision is now accepted and ready to land.Jan 9 2019, 12:29 PM
This revision was automatically updated to reflect the committed changes.