Skip to content

Commit 432010a

Browse files
authored
Merge pull request #11002 from swiftlang/feature-availability-forward-declaration
[feature availability] Don't disallow annotating ObjC interfaces and protocols with features when there are unannotated forward declarations of them
2 parents c56cc49 + fe0fe92 commit 432010a

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
@@ -3658,11 +3658,27 @@ void Sema::copyFeatureAvailability(Decl *Dst, Decl *Src) {
36583658
}
36593659
}
36603660

3661+
static bool isForwardDeclaration(Decl *Prev, Decl *D) {
3662+
if (Prev->getCanonicalDecl() != D->getCanonicalDecl())
3663+
return false;
3664+
if (auto *ID = dyn_cast<ObjCInterfaceDecl>(Prev))
3665+
return !ID->getPreviousDecl();
3666+
if (auto *PD = dyn_cast<ObjCProtocolDecl>(Prev))
3667+
return !PD->getPreviousDecl();
3668+
return false;
3669+
}
3670+
36613671
void Sema::copyFeatureAvailabilityCheck(Decl *Dst, NamedDecl *Src,
36623672
bool Redeclaration) {
36633673
if (Dst->isInvalidDecl())
36643674
return;
36653675

3676+
// Don't check whether a new feature is being added if Src is a
3677+
// forward declaration of classes and protocols as they cannnot be
3678+
// annotated with attributes.
3679+
if (isForwardDeclaration(Src, Dst))
3680+
return;
3681+
36663682
llvm::SmallDenseMap<StringRef, DomainAvailabilityAttr *> DstToAttr;
36673683

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