Skip to content

Commit 2fcad59

Browse files
committed
[interop] <swift/bridging> guard macros using has_attribute to make this header usable with GCC and MSVC
1 parent b55bc19 commit 2fcad59

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

lib/ClangImporter/bridging

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@
1818
#ifndef SWIFT_CLANGIMPORTER_SWIFT_INTEROP_SUPPORT_H
1919
#define SWIFT_CLANGIMPORTER_SWIFT_INTEROP_SUPPORT_H
2020

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+
2129
/// Specifies that a C++ `class` or `struct` owns and controls the lifetime of all
2230
/// of the objects it references. Such type should not reference any objects whose
2331
/// lifetime is controlled externally. This annotation allows Swift to import methods
@@ -125,4 +133,20 @@
125133
#define SWIFT_COMPUTED_PROPERTY \
126134
__attribute__((swift_attr("import_computed_property")))
127135

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+
128152
#endif // SWIFT_CLANGIMPORTER_SWIFT_INTEROP_SUPPORT_H

0 commit comments

Comments
 (0)