Forming UnsafePointer unwanted warning

Is it possible to suppress this warning?

class C {}

struct S {
    var i = 0
    var c = C()
}

var a = S()
func foo(_ v: UnsafeRawPointer) {}
foo(&a)
// 🔶 Warning: Forming 'UnsafeRawPointer' to a variable of type 'S';
// this is likely incorrect because 'S' may contain an object reference.

Can you use the scoped withUnsafePointer API?

class C {}

struct S {
    var i = 0
    var c = C()
}

var a = S()
func foo(_ v: UnsafeRawPointer) {}

withUnsafePointer(to: &a) { p in
    foo(p)
}
2 Likes

This is issue: Constrain implicit raw pointer conversion to bitwise-copyable values · Issue #64927 · apple/swift · GitHub
Workarounds: swift-evolution/proposals/nnnn-implicit-raw-bitwise-conversion.md at diagnose-implicit-raw-bitwise · atrick/swift-evolution · GitHub

2 Likes