Skip to content

Commit bee6a76

Browse files
committed
[ObjC] Avoid the -Wunguarded-availability warnings for protocol
requirements in protocol/class/category declarations The unguarded availability warnings in the protocol requirements of a protocol /class/category declaration can be avoided. This matches the behaviour of Swift's diagnostics. The warnings for deprecated/unavailable protocols are preserved. rdar://33156429 Differential Revision: https://reviews.llvm.org/D35061 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@307368 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent a903edb commit bee6a76

File tree

4 files changed

+39
-6
lines changed

4 files changed

+39
-6
lines changed

include/clang/Sema/Sema.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3900,8 +3900,9 @@ class Sema {
39003900

39013901
bool CanUseDecl(NamedDecl *D, bool TreatUnavailableAsInvalid);
39023902
bool DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc,
3903-
const ObjCInterfaceDecl *UnknownObjCClass=nullptr,
3904-
bool ObjCPropertyAccess=false);
3903+
const ObjCInterfaceDecl *UnknownObjCClass = nullptr,
3904+
bool ObjCPropertyAccess = false,
3905+
bool AvoidPartialAvailabilityChecks = false);
39053906
void NoteDeletedFunction(FunctionDecl *FD);
39063907
void NoteDeletedInheritingConstructor(CXXConstructorDecl *CD);
39073908
std::string getDeletedOrUnavailableSuffix(const FunctionDecl *FD);

lib/Sema/SemaDeclObjC.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,10 @@ static void diagnoseUseOfProtocols(Sema &TheSema,
458458
// Diagnose availability in the context of the ObjC container.
459459
Sema::ContextRAII SavedContext(TheSema, CD);
460460
for (unsigned i = 0; i < NumProtoRefs; ++i) {
461-
(void)TheSema.DiagnoseUseOfDecl(ProtoRefs[i], ProtoLocs[i]);
461+
(void)TheSema.DiagnoseUseOfDecl(ProtoRefs[i], ProtoLocs[i],
462+
/*UnknownObjCClass=*/nullptr,
463+
/*ObjCPropertyAccess=*/false,
464+
/*AvoidPartialAvailabilityChecks=*/true);
462465
}
463466
}
464467

lib/Sema/SemaExpr.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ Sema::ShouldDiagnoseAvailabilityOfDecl(const NamedDecl *D,
128128
static void
129129
DiagnoseAvailabilityOfDecl(Sema &S, NamedDecl *D, SourceLocation Loc,
130130
const ObjCInterfaceDecl *UnknownObjCClass,
131-
bool ObjCPropertyAccess) {
131+
bool ObjCPropertyAccess,
132+
bool AvoidPartialAvailabilityChecks = false) {
132133
std::string Message;
133134
AvailabilityResult Result;
134135
const NamedDecl* OffendingDecl;
@@ -138,6 +139,8 @@ DiagnoseAvailabilityOfDecl(Sema &S, NamedDecl *D, SourceLocation Loc,
138139
return;
139140

140141
if (Result == AR_NotYetIntroduced) {
142+
if (AvoidPartialAvailabilityChecks)
143+
return;
141144
if (S.getCurFunctionOrMethodDecl()) {
142145
S.getEnclosingFunction()->HasPotentialAvailabilityViolations = true;
143146
return;
@@ -275,7 +278,8 @@ void Sema::MaybeSuggestAddingStaticToDecl(const FunctionDecl *Cur) {
275278
///
276279
bool Sema::DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc,
277280
const ObjCInterfaceDecl *UnknownObjCClass,
278-
bool ObjCPropertyAccess) {
281+
bool ObjCPropertyAccess,
282+
bool AvoidPartialAvailabilityChecks) {
279283
if (getLangOpts().CPlusPlus && isa<FunctionDecl>(D)) {
280284
// If there were any diagnostics suppressed by template argument deduction,
281285
// emit them now.
@@ -360,7 +364,8 @@ bool Sema::DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc,
360364
}
361365

362366
DiagnoseAvailabilityOfDecl(*this, D, Loc, UnknownObjCClass,
363-
ObjCPropertyAccess);
367+
ObjCPropertyAccess,
368+
AvoidPartialAvailabilityChecks);
364369

365370
DiagnoseUnusedOfDecl(*this, D, Loc);
366371

test/SemaObjC/unguarded-availability.m

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,3 +263,27 @@ void with_local_struct() {
263263
new_int x; // expected-warning{{'new_int' is partial}}
264264
};
265265
}
266+
267+
// rdar://33156429:
268+
// Avoid the warning on protocol requirements.
269+
270+
AVAILABLE_10_12
271+
@protocol NewProtocol // expected-note {{'NewProtocol' has been explicitly marked partial here}}
272+
@end
273+
274+
@protocol ProtocolWithNewProtocolRequirement <NewProtocol> // expected-note {{annotate 'ProtocolWithNewProtocolRequirement' with an availability attribute to silence}}
275+
276+
@property(copy) id<NewProtocol> prop; // expected-warning {{'NewProtocol' is partial: introduced in macOS 10.12}}
277+
278+
@end
279+
280+
@interface BaseClass
281+
@end
282+
283+
@interface ClassWithNewProtocolRequirement : BaseClass <NewProtocol>
284+
285+
@end
286+
287+
@interface BaseClass (CategoryWithNewProtocolRequirement) <NewProtocol>
288+
289+
@end

0 commit comments

Comments
 (0)