swift icon indicating copy to clipboard operation
swift copied to clipboard

Tracking issue to list all known issues related to C++ interoperability support in Swift 5.9

Open hyp opened this issue 2 years ago • 2 comments

This issue contains a list of all known limitations and other issues related to C++ interoperability support in the Swift 5.9 release of Swift. Not known issues are not listed here, so if you see something please report a new issue.

Note: Swift 5.9 is still undergoing development, and therefore some limitations and issues listed here will be fixed before Swift 5.9 is release. Please see the following tracking issue you'd like to see which issues we plan on fixing in Swift 5.9.


Issues Related to Using C++ APIs in Swift 5.9

Some functions or member functions whose return type is not yet available in Swift, or not exported by the Clang module could appear to be available and callable from Swift, with the Never return type. Such functions should not be available in Swift, and should not be called : https://github.com/apple/swift/issues/64401 .

Default arguments in C++ functions are not mapped to default arguments in Swift functions or methods.

Functions inside inline namespaces must be accessed using the inline namespace qualifier from Swift due to: https://github.com/apple/swift/issues/58217 .

Issues Related to C++ Member Functions

C++ constant member functions that mutate the object using a mutable field cannot be annotated with SWIFT_MUTATING. This means that the user has no way to import it as mutating Swift method, and as such such member functions should generally not be called in Swift. This issue tracks the addition of SWIFT_MUTATING macro to the <swift/bridging> header: https://github.com/apple/swift/issues/66322.

Specifically on the Windows deployment platform, some member functions might be dispatched incorrectly: https://github.com/apple/swift/issues/66326

Issues Related to Accessing Inherited Members

Swift compiler might introduce ambiguous method overloads when adding a C++ member from a base a C++ class to the Swift type that represents the C++ class or structure. This issue tracks the clarification of related rules which should resolve the problem, and gives an example of when such issue might occur: https://github.com/apple/swift/issues/66323

Issues Related to C or Objective-C compatibility

Objective-C options sets, like NSTrackingArea import incorrectly when C++ interoperability is enabled: https://github.com/apple/swift/issues/65885

Use of some Objective-C Foundation functions, like URL.bookmark() might lead to linking errors: https://github.com/apple/swift/issues/66501

A trivial C++ structure or class that has only Objective-C ARC object pointers as fields can be incorrectly passed to an Objective-C method call when C++ interop is enabled (on Intel): https://github.com/apple/swift/issues/61929 .

On Linux, you cannot import Foundation when C++ interop is enabled: https://github.com/apple/swift/issues/64457

Known Compiler Crashes In Swift Related to C++ Interoperability

  • https://github.com/apple/swift/issues/65891
  • when indexing is enabled on Linux: https://github.com/apple/swift/issues/65646

Issues Related to Using Swift APIs in C++

Swift functions and methods are exposed to C++ using just their base name, and argument labels aren't factored into the C++ function name. Only one function / method with the same base name and same number of parameters is exposed to C++. For example, given the following two functions:

func print(company: Int) {}
func print(person: String) {}

Only one of them is available in C++.

Issues Related to Using Swift Structures or Enumerations in C++

Swift structures and enumerations currently can't use the copy-assignment operator in C++, i.e. they can't be reassigned after they're initialized: https://github.com/apple/swift/issues/66324.

Swift structures and enumerations cannot be moved in C++. That is, you can't use std::move on a Swift structure or enumeration to move a value to a new value using a move constructor or a move assignment operator.

Issues Related to Using Swift Generics in C++

Swift generic structure or enumeration might fail to work with the Swift Int type as a generic type parameter in C++: https://github.com/apple/swift/issues/63452 .


Issues Related to Swift Package Manager Support For C++ Interoperability

  • https://github.com/apple/swift-package-manager/issues/6565

Issues Related to IDE Support

Code-completion for C++ namespace members in Swift is not yet supported: https://github.com/apple/swift/issues/65736 .

hyp avatar May 26 '23 00:05 hyp

Is support for default arguments a target or not?

mickeyl avatar Jun 09 '23 14:06 mickeyl

Is support for default arguments a target or not?

Not for Swift 5.9

hyp avatar Jun 09 '23 16:06 hyp