Skip to content

Commit e95b66e

Browse files
committed
[cxx-interop] Teach clang to ignore availability errors that come from CF_OPTIONS.
1 parent c1148a1 commit e95b66e

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

clang/lib/Sema/SemaAvailability.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,18 @@ ShouldDiagnoseAvailabilityInContext(Sema &S, AvailabilityResult K,
122122
const NamedDecl *OffendingDecl) {
123123
assert(K != AR_Available && "Expected an unavailable declaration here!");
124124

125+
// If this was defined using CF_OPTIONS, etc. then ignore the diagnostic.
126+
auto DeclLoc = Ctx->getBeginLoc();
127+
// This is only a problem in Foundation's C++ implementation for CF_OPTIONS.
128+
if (DeclLoc.isMacroID() && S.getLangOpts().CPlusPlus &&
129+
isa<TypedefDecl>(OffendingDecl)) {
130+
StringRef MacroName = S.getPreprocessor().getImmediateMacroName(DeclLoc);
131+
if (MacroName == "CF_OPTIONS" || MacroName == "OBJC_OPTIONS" ||
132+
MacroName == "SWIFT_OPTIONS" || MacroName == "NS_OPTIONS") {
133+
return false;
134+
}
135+
}
136+
125137
// Checks if we should emit the availability diagnostic in the context of C.
126138
auto CheckContext = [&](const Decl *C) {
127139
if (K == AR_NotYetIntroduced) {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: %clang_cc1 -fsyntax-only -verify %s
2+
// expected-no-diagnostics
3+
4+
#define CF_OPTIONS(_type, _name) __attribute__((availability(swift, unavailable))) _type _name; enum : _name
5+
6+
__attribute__((availability(macOS, unavailable)))
7+
typedef CF_OPTIONS(unsigned, TestOptions) {
8+
x
9+
};

0 commit comments

Comments
 (0)