Index: clang/lib/Sema/SemaDeclAttr.cpp =================================================================== --- clang/lib/Sema/SemaDeclAttr.cpp +++ clang/lib/Sema/SemaDeclAttr.cpp @@ -7716,6 +7716,15 @@ } } + // If this entity was declared in an Objective-C category then infer its + // availability from the category's availability. + if (auto *CatDecl = dyn_cast(D->getDeclContext())) { + if (Result == AR_Available) { + Result = CatDecl->getAvailability(Message); + D = CatDecl; + } + } + return {Result, D}; } Index: clang/test/SemaObjC/unguarded-availability.m =================================================================== --- clang/test/SemaObjC/unguarded-availability.m +++ clang/test/SemaObjC/unguarded-availability.m @@ -353,3 +353,41 @@ void is_destructor() { func_10_11(); // expected-warning{{'func_10_11' is only available on macOS 10.11 or newer}} expected-note{{enclose 'func_10_11' in an @available check to silence this warning}} } + +@interface HasCat +-(void)meth; ++(void)class_meth; +@property int prop; +@end + +AVAILABLE_10_11 +// FIXME: The pretty-printing for categories sucks. +@interface HasCat () // expected-note 3 {{'' has been marked as being introduced in macOS 10.11 here, but the deployment target is macOS 10.9.0}} +-(void)meth1; ++(void)class_meth1; + +@property int prop1; + +@end + +AVAILABLE_10_12 +@interface HasCat (Named) // expected-note{{'Named' has been marked as being introduced in macOS 10.12 here, but the deployment target is macOS 10.9.0}} +-(void)meth2; +@end + +@interface HasCat (OtherNamed) +-(void)meth3; +@end + +void test_category(HasCat *hc) { + [hc meth]; + [hc meth1]; // expected-warning{{'meth1' is only available on macOS 10.11 or newer}} expected-note{{enclose 'meth1' in an @available check to silence this warning}} + [hc meth2]; // expected-warning{{'meth2' is only available on macOS 10.12 or newer}} expected-note{{enclose 'meth2' in an @available check to silence this warning}} + [hc meth3]; + + [HasCat class_meth]; + [HasCat class_meth1]; // expected-warning{{'class_meth1' is only available on macOS 10.11 or newer}} expected-note{{enclose 'class_meth1' in an @available check to silence this warning}} + + hc.prop = 42; + hc.prop1 = 42; // expected-warning{{'setProp1:' is only available on macOS 10.11 or newer}} expected-note{{enclose 'setProp1:' in an @available check to silence this warning}} +}