Skip to content

[Changelog] Add entry for unsound pointer diagnostics #28109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,39 @@ CHANGELOG
Swift 5.2
---------

* [SR-2790][]:

The compiler will now emit a warning when attempting to pass a temporary
pointer argument produced from an array, string, or inout argument to a
parameter which is known to escape it. This includes the various initializers
for the `UnsafePointer`/`UnsafeBufferPointer` family of types, as well as
memberwise initializers.

```swift
struct S {
var ptr: UnsafePointer<Int8>
}

func foo() {
var i: Int8 = 0
let ptr = UnsafePointer(&i)
// warning: initialization of 'UnsafePointer<Int8>' results in a
// dangling pointer

let s1 = S(ptr: [1, 2, 3])
// warning: passing '[Int8]' to parameter, but argument 'ptr' should be a
// pointer that outlives the call to 'init(ptr:)'

let s2 = S(ptr: "hello")
// warning: passing 'String' to parameter, but argument 'ptr' should be a
// pointer that outlives the call to 'init(ptr:)'
}
```

All 3 of the above examples are unsound because each argument produces a
temporary pointer only valid for the duration of the call they are passed to.
Therefore the returned value in each case references a dangling pointer.

* [SR-2189][]:

The compiler now supports local functions whose default arguments capture
Expand Down Expand Up @@ -7824,6 +7857,7 @@ Swift 1.0
[SR-2608]: <https://bugs.swift.org/browse/SR-2608>
[SR-2672]: <https://bugs.swift.org/browse/SR-2672>
[SR-2688]: <https://bugs.swift.org/browse/SR-2688>
[SR-2790]: <https://bugs.swift.org/browse/SR-2790>
[SR-4206]: <https://bugs.swift.org/browse/SR-4206>
[SR-4248]: <https://bugs.swift.org/browse/SR-4248>
[SR-5581]: <https://bugs.swift.org/browse/SR-5581>
Expand Down