Skip to content

Commit ea01b75

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 4095d2d commit ea01b75

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
@@ -4018,11 +4018,27 @@ void Sema::copyFeatureAvailability(Decl *Dst, Decl *Src) {
40184018
}
40194019
}
40204020

4021+
static bool isForwardDeclaration(Decl *Prev, Decl *D) {
4022+
if (Prev->getCanonicalDecl() != D->getCanonicalDecl())
4023+
return false;
4024+
if (auto *ID = dyn_cast<ObjCInterfaceDecl>(Prev))
4025+
return !ID->getPreviousDecl();
4026+
if (auto *PD = dyn_cast<ObjCProtocolDecl>(Prev))
4027+
return !PD->getPreviousDecl();
4028+
return false;
4029+
}
4030+
40214031
void Sema::copyFeatureAvailabilityCheck(Decl *Dst, NamedDecl *Src,
40224032
bool Redeclaration) {
40234033
if (Dst->isInvalidDecl())
40244034
return;
40254035

4036+
// Don't check whether a new feature is being added if Src is a
4037+
// forward declaration of classes and protocols as they cannnot be
4038+
// annotated with attributes.
4039+
if (isForwardDeclaration(Src, Dst))
4040+
return;
4041+
40264042
llvm::SmallDenseMap<StringRef, DomainAvailabilityAttr *> DstToAttr;
40274043

40284044
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)