Skip to content

Commit e4d4627

Browse files
committed
[BitwiseCopyable] Inference for imported types.
1 parent 0303bea commit e4d4627

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

proposals/nnnn-bitwise-copyable.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,20 @@ If this is desired, the developer can explicitly write the conditional conforman
150150

151151
[^2]: This includes raw-value enums. While such enums do include a conformance to `RawRepresentable` where `RawValue` could be a non-conforming type (`String`), the instances of the enums themselves are `BitwiseCopyable`.
152152

153+
### Inference for imported types
154+
155+
The same inference will be done on imported C and C++ types.
156+
157+
For an imported C or C++ enum, the compiler will always generate a conformance to to `BitwiseCopyable`.
158+
159+
For an imported C struct, if all its fields are `BitwiseCopyable`, the compiler will generate a conformance to `BitwiseCopyable`.
160+
The same is true for an imported C++ struct or class, unless the type is non-trivial[^3].
161+
162+
For an imported C or C++ struct, if any of its fields cannot be represented in Swift, the compiler will not generate a conformance.
163+
This can be overridden, however, by annotating the type `__attribute__((__swift_attr__("_BitwiseCopyable")))`.
164+
165+
[^3]: A C++ type is considered non-trivial (for the purpose of calls, as defined by the Itanium ABI) if any of the following is non-default: its constructor; its copy-constructor; its destructor.
166+
153167
### Inference for exported types
154168

155169
This does not apply to exported (`public`, `package`, or `@usableFromInline`) types.

0 commit comments

Comments
 (0)