From 770e87e92de742da83502bdc273241f76200e84e Mon Sep 17 00:00:00 2001 From: Akira Hatanaka Date: Sat, 12 Jul 2025 10:10:51 -0700 Subject: [PATCH] [feature availability] Don't warn about unguarded uses of ObjC protocols adopted by interfaces We don't want to force users to annotate interfaces/protocols/categories adopting the annotated protocol with feature attributes. rdar://155690040 --- clang/lib/Sema/SemaExpr.cpp | 3 ++- clang/test/SemaObjC/feature-availability.m | 8 +++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 23c46a7da9c67..448135c2965b7 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -377,7 +377,8 @@ bool Sema::DiagnoseUseOfDecl(NamedDecl *D, ArrayRef Locs, DiagnoseAvailabilityOfDecl(D, Locs, UnknownObjCClass, ObjCPropertyAccess, AvoidPartialAvailabilityChecks, ClassReceiver); - DiagnoseFeatureAvailabilityOfDecl(D, Locs); + if (!AvoidPartialAvailabilityChecks) + DiagnoseFeatureAvailabilityOfDecl(D, Locs); DiagnoseUnusedOfDecl(*this, D, Loc); diff --git a/clang/test/SemaObjC/feature-availability.m b/clang/test/SemaObjC/feature-availability.m index 586b60b24fb65..99fc708bc022e 100644 --- a/clang/test/SemaObjC/feature-availability.m +++ b/clang/test/SemaObjC/feature-availability.m @@ -147,7 +147,7 @@ @interface Base3 @end __attribute__((availability(domain:feature1, AVAIL))) -@interface Base4 // expected-error {{use of 'P1' requires feature 'feature1' to be unavailable}} +@interface Base4 @end __attribute__((availability(domain:feature1, AVAIL))) @@ -166,8 +166,10 @@ @interface Base5(Cat3) @end __attribute__((availability(domain:feature1, UNAVAIL))) -@interface Base5(Cat4) // expected-error {{use of 'P2' requires feature 'feature1' to be available}} +@interface Base5(Cat4) @end -@interface Base6 // expected-error {{use of 'P1' requires feature 'feature1' to be unavailable}} expected-error {{use of 'P2' requires feature 'feature1' to be available}} +@interface Base6 @end + +void foo(id); // expected-error {{use of 'P1' requires feature 'feature1' to be unavailable}}