Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cxx-interop] Teach clang to ignore availability errors that come from CF_OPTIONS. #6431

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions clang/lib/Sema/SemaAvailability.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,18 @@ ShouldDiagnoseAvailabilityInContext(Sema &S, AvailabilityResult K,
const NamedDecl *OffendingDecl) {
assert(K != AR_Available && "Expected an unavailable declaration here!");

// If this was defined using CF_OPTIONS, etc. then ignore the diagnostic.
auto DeclLoc = Ctx->getBeginLoc();
// This is only a problem in Foundation's C++ implementation for CF_OPTIONS.
if (DeclLoc.isMacroID() && S.getLangOpts().CPlusPlus &&
isa<TypedefDecl>(OffendingDecl)) {
StringRef MacroName = S.getPreprocessor().getImmediateMacroName(DeclLoc);
if (MacroName == "CF_OPTIONS" || MacroName == "OBJC_OPTIONS" ||
MacroName == "SWIFT_OPTIONS" || MacroName == "NS_OPTIONS") {
return false;
}
}

// Checks if we should emit the availability diagnostic in the context of C.
auto CheckContext = [&](const Decl *C) {
if (K == AR_NotYetIntroduced) {
Expand Down
9 changes: 9 additions & 0 deletions clang/test/SemaCXX/suppress-availability-error-cf-options.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// RUN: %clang_cc1 -fsyntax-only -verify %s
// expected-no-diagnostics

#define CF_OPTIONS(_type, _name) __attribute__((availability(swift, unavailable))) _type _name; enum : _name

__attribute__((availability(macOS, unavailable)))
typedef CF_OPTIONS(unsigned, TestOptions) {
x
};