Skip to content

Commit 3e89c4d

Browse files
authored
Merge pull request #65589 from hyp/eng/bridging-header-fixups
[interop] update <swift/bridging> to have language comment and __has_attribute guard
2 parents 646f16d + 2fcad59 commit 3e89c4d

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

lib/ClangImporter/bridging

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// -*- C++ -*-
12
//===------------------ bridging - C++ and Swift Interop --------*- C++ -*-===//
23
//
34
// This source file is part of the Swift.org open source project
@@ -17,6 +18,14 @@
1718
#ifndef SWIFT_CLANGIMPORTER_SWIFT_INTEROP_SUPPORT_H
1819
#define SWIFT_CLANGIMPORTER_SWIFT_INTEROP_SUPPORT_H
1920

21+
#ifdef __has_attribute
22+
#define _CXX_INTEROP_HAS_ATTRIBUTE(x) __has_attribute(x)
23+
#else
24+
#define _CXX_INTEROP_HAS_ATTRIBUTE(x) 0
25+
#endif
26+
27+
#if _CXX_INTEROP_HAS_ATTRIBUTE(swift_attr)
28+
2029
/// Specifies that a C++ `class` or `struct` owns and controls the lifetime of all
2130
/// of the objects it references. Such type should not reference any objects whose
2231
/// lifetime is controlled externally. This annotation allows Swift to import methods
@@ -124,4 +133,20 @@
124133
#define SWIFT_COMPUTED_PROPERTY \
125134
__attribute__((swift_attr("import_computed_property")))
126135

136+
#else // #if _CXX_INTEROP_HAS_ATTRIBUTE(swift_attr)
137+
138+
// Empty defines for compilers that don't support `attribute(swift_attr)`.
139+
#define SWIFT_SELF_CONTAINED
140+
#define SWIFT_RETURNS_INDEPENDENT_VALUE
141+
#define SWIFT_SHARED_REFERENCE(_retain, _release)
142+
#define SWIFT_IMMORTAL_REFERENCE
143+
#define SWIFT_UNSAFE_REFERENCE
144+
#define SWIFT_NAME(_name)
145+
#define SWIFT_CONFORMS_TO_PROTOCOL(_moduleName_protocolName)
146+
#define SWIFT_COMPUTED_PROPERTY
147+
148+
#endif // #if _CXX_INTEROP_HAS_ATTRIBUTE(swift_attr)
149+
150+
#undef _CXX_INTEROP_HAS_ATTRIBUTE
151+
127152
#endif // SWIFT_CLANGIMPORTER_SWIFT_INTEROP_SUPPORT_H

0 commit comments

Comments
 (0)