Skip to content

Commit b14c2f0

Browse files
committed
[feature availability] Don't disallow annotating ObjC interfaces and
protocols with features when there are unannotated forward declarations of them clang shouldn't reject this as forward delarations of ObjC interfaces and protocols cannot be annotated with attributes. rdar://154522966
1 parent e14778b commit b14c2f0

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3958,11 +3958,27 @@ void Sema::copyFeatureAvailability(Decl *Dst, Decl *Src) {
39583958
}
39593959
}
39603960

3961+
static bool isForwardDeclaration(Decl *Prev, Decl *D) {
3962+
if (Prev->getCanonicalDecl() != D->getCanonicalDecl())
3963+
return false;
3964+
if (auto *ID = dyn_cast<ObjCInterfaceDecl>(Prev))
3965+
return !ID->getPreviousDecl();
3966+
if (auto *PD = dyn_cast<ObjCProtocolDecl>(Prev))
3967+
return !PD->getPreviousDecl();
3968+
return false;
3969+
}
3970+
39613971
void Sema::copyFeatureAvailabilityCheck(Decl *Dst, NamedDecl *Src,
39623972
bool Redeclaration) {
39633973
if (Dst->isInvalidDecl())
39643974
return;
39653975

3976+
// Don't check whether a new feature is being added if Src is a
3977+
// forward declaration of classes and protocols as they cannnot be
3978+
// annotated with attributes.
3979+
if (isForwardDeclaration(Src, Dst))
3980+
return;
3981+
39663982
llvm::SmallDenseMap<StringRef, DomainAvailabilityAttr *> DstToAttr;
39673983

39683984
for (auto *AA : Dst->specific_attrs<DomainAvailabilityAttr>())

clang/test/SemaObjC/feature-availability.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ -(struct S1)m2 __attribute__((availability(domain:feature1, AVAIL)));
3434
-(struct S1)m3 __attribute__((availability(domain:feature1, UNAVAIL))); // expected-error {{use of 'S1' requires feature 'feature1' to be available}}
3535
@end
3636

37+
@class Base0;
38+
3739
__attribute__((availability(domain:feature1, AVAIL))) // expected-note 2 {{is incompatible with __attribute__((availability(domain:feature1, 0)))}}
3840
@interface Base0 {
3941
struct S0 ivar0; // expected-error {{use of 'S0' requires feature 'feature1' to be unavailable}}
@@ -134,6 +136,8 @@ @interface Derived2(Cat1)
134136
@implementation Derived2(Cat1)
135137
@end
136138

139+
@protocol P1;
140+
137141
__attribute__((availability(domain:feature1, UNAVAIL)))
138142
@protocol P1
139143
@end

0 commit comments

Comments
 (0)