From: Alex Lorenz Date: Fri, 23 Feb 2018 23:49:43 +0000 (+0000) Subject: [Sema][ObjC] Process category attributes before checking protocol uses X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=af90db31b5d1f45d3fae06dd30fc4889e501f85a;p=clang [Sema][ObjC] Process category attributes before checking protocol uses This ensures that any availability attributes are attached to the category before the availability for the referenced protocols is checked. rdar://37829755 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@325994 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp index c17fde497a..cab6a50629 100644 --- a/lib/Sema/SemaDeclObjC.cpp +++ b/lib/Sema/SemaDeclObjC.cpp @@ -1835,6 +1835,13 @@ ActOnStartCategoryInterface(SourceLocation AtInterfaceLoc, // FIXME: PushOnScopeChains? CurContext->addDecl(CDecl); + // Process the attributes before looking at protocols to ensure that the + // availability attribute is attached to the category to provide availability + // checking for protocol uses. + if (AttrList) + ProcessDeclAttributeList(TUScope, CDecl, AttrList); + AddPragmaAttributes(TUScope, CDecl); + if (NumProtoRefs) { diagnoseUseOfProtocols(*this, CDecl, (ObjCProtocolDecl*const*)ProtoRefs, NumProtoRefs, ProtoLocs); @@ -1846,10 +1853,6 @@ ActOnStartCategoryInterface(SourceLocation AtInterfaceLoc, NumProtoRefs, Context); } - if (AttrList) - ProcessDeclAttributeList(TUScope, CDecl, AttrList); - AddPragmaAttributes(TUScope, CDecl); - CheckObjCDeclScope(CDecl); return ActOnObjCContainerStartDefinition(CDecl); } diff --git a/test/SemaObjC/unguarded-availability-category-protocol-use.m b/test/SemaObjC/unguarded-availability-category-protocol-use.m new file mode 100644 index 0000000000..d2eb9f4841 --- /dev/null +++ b/test/SemaObjC/unguarded-availability-category-protocol-use.m @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -triple arm64-apple-ios10 -Wunguarded-availability -fblocks -fsyntax-only -verify %s + +__attribute__((availability(ios,unavailable))) +@protocol Prot // expected-note {{here}} + +@end + +@interface A +@end + +__attribute__((availability(ios,unavailable))) +@interface A (Cat) // No error. +@end + +__attribute__((availability(tvos,unavailable))) +@interface B @end +@interface B (Cat) // expected-error {{'Prot' is unavailable: not available on iOS}} +@end