Skip to content

C++ interop: Pointer to pointer imported as ?! in Swift when using SWIFT_UNSAFE_REFERENCE #70818

@0xpablo

Description

@0xpablo

Description

I'm facing an issue with C++ interoperability when trying to use a class that comes from C++ in Swift due to importing a pointer to pointer as ?! instead of unsafe pointers, which makes some C++ code impossible to use.

More context on this swift forum post.

Reproduction

#include <swift/bridging>

class DB {
public:
   void openDB(DB**); 
} SWIFT_UNSAFE_REFERENCE;

is imported as

@available(macOS 13.3.0, *)
public class DB {   
    public func openDB(_: DB?!)
}

Expected behavior

That the API is imported using unsafe pointers so that I can do this:

var db: DB = nil
openDB(&db)

Environment

swift-driver version: 1.87.3 Apple Swift version 5.9.2 (swiftlang-5.9.2.2.56 clang-1500.1.0.2.5)

(I also tried with a 5.10 snapshot from Dec 19 with the same result).

Additional information

No response

Metadata

Metadata

Assignees

Labels

bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.c++ interopFeature: Interoperability with C++c++ to swiftFeature → c++ interop: c++ to swiftclang importerArea → compiler: The clang importercompilerThe Swift compiler itselfswift 5.10unexpected behaviorBug: Unexpected behavior or incorrect output

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions