Skip to content

Commit f2564d5

Browse files
committed
[stdlib] Add a couple of missing @_nonEphemeral attributes
1 parent 21e9307 commit f2564d5

3 files changed

+50
-8
lines changed

stdlib/public/core/BridgeObjectiveC.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ public struct AutoreleasingUnsafeMutablePointer<Pointee /* TODO : class */>
485485
/// - Warning: Accessing `pointee` as a type that is unrelated to
486486
/// the underlying memory's bound type is undefined.
487487
@_transparent
488-
public init<U>(_ from: UnsafeMutablePointer<U>) {
488+
public init<U>(@_nonEphemeral _ from: UnsafeMutablePointer<U>) {
489489
self._rawValue = from._rawValue
490490
}
491491

@@ -500,7 +500,7 @@ public struct AutoreleasingUnsafeMutablePointer<Pointee /* TODO : class */>
500500
/// - Warning: Accessing `pointee` as a type that is unrelated to
501501
/// the underlying memory's bound type is undefined.
502502
@_transparent
503-
public init?<U>(_ from: UnsafeMutablePointer<U>?) {
503+
public init?<U>(@_nonEphemeral _ from: UnsafeMutablePointer<U>?) {
504504
guard let unwrapped = from else { return nil }
505505
self.init(unwrapped)
506506
}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,31 @@
11
// RUN: %target-typecheck-verify-swift -enable-invalid-ephemeralness-as-error
22
// REQUIRES: objc_interop
33

4+
class C {}
5+
46
func unsafePointerInitEphemeralConversions() {
5-
class C {}
6-
var c: C?
7+
var c = C()
8+
var optC: C?
9+
10+
_ = AutoreleasingUnsafeMutablePointer(&c) // expected-error {{initialization of 'AutoreleasingUnsafeMutablePointer<C>' results in a dangling pointer}}
11+
// expected-note@-1 {{implicit argument conversion from 'C' to 'AutoreleasingUnsafeMutablePointer<C>' produces a pointer valid only for the duration of the call to 'init(_:)'}}
12+
13+
_ = AutoreleasingUnsafeMutablePointer<AnyObject>(&c) // expected-error {{initialization of 'AutoreleasingUnsafeMutablePointer<AnyObject>' results in a dangling pointer}}
14+
// expected-note@-1 {{implicit argument conversion from 'C' to 'UnsafeMutablePointer<C>' produces a pointer valid only for the duration of the call to 'init(_:)'}}
15+
// expected-note@-2 {{use 'withUnsafeMutablePointer' in order to explicitly convert argument to pointer valid for a defined scope}}
716

8-
_ = AutoreleasingUnsafeMutablePointer(&c) // expected-error {{initialization of 'AutoreleasingUnsafeMutablePointer<C?>' results in a dangling pointer}}
17+
_ = AutoreleasingUnsafeMutablePointer(&optC) // expected-error {{initialization of 'AutoreleasingUnsafeMutablePointer<C?>' results in a dangling pointer}}
918
// expected-note@-1 {{implicit argument conversion from 'C?' to 'AutoreleasingUnsafeMutablePointer<C?>' produces a pointer valid only for the duration of the call to 'init(_:)'}}
19+
20+
_ = AutoreleasingUnsafeMutablePointer<C>(&optC) // expected-error {{initialization of 'AutoreleasingUnsafeMutablePointer<C>' results in a dangling pointer}}
21+
// expected-note@-1 {{implicit argument conversion from 'C?' to 'UnsafeMutablePointer<C?>' produces a pointer valid only for the duration of the call to 'init(_:)'}}
22+
// expected-note@-2 {{use 'withUnsafeMutablePointer' in order to explicitly convert argument to pointer valid for a defined scope}}
23+
24+
_ = AutoreleasingUnsafeMutablePointer<AnyObject>(&optC) // expected-error {{initialization of 'AutoreleasingUnsafeMutablePointer<AnyObject>' results in a dangling pointer}}
25+
// expected-note@-1 {{implicit argument conversion from 'C?' to 'UnsafeMutablePointer<C?>' produces a pointer valid only for the duration of the call to 'init(_:)'}}
26+
// expected-note@-2 {{use 'withUnsafeMutablePointer' in order to explicitly convert argument to pointer valid for a defined scope}}
27+
28+
_ = AutoreleasingUnsafeMutablePointer<AnyObject?>(&optC) // expected-error {{initialization of 'AutoreleasingUnsafeMutablePointer<AnyObject?>' results in a dangling pointer}}
29+
// expected-note@-1 {{implicit argument conversion from 'C?' to 'UnsafeMutablePointer<C?>' produces a pointer valid only for the duration of the call to 'init(_:)'}}
30+
// expected-note@-2 {{use 'withUnsafeMutablePointer' in order to explicitly convert argument to pointer valid for a defined scope}}
1031
}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,31 @@
11
// RUN: %target-typecheck-verify-swift
22
// REQUIRES: objc_interop
33

4+
class C {}
5+
46
func unsafePointerInitEphemeralConversions() {
5-
class C {}
6-
var c: C?
7+
var c = C()
8+
var optC: C?
9+
10+
_ = AutoreleasingUnsafeMutablePointer(&c) // expected-warning {{initialization of 'AutoreleasingUnsafeMutablePointer<C>' results in a dangling pointer}}
11+
// expected-note@-1 {{implicit argument conversion from 'C' to 'AutoreleasingUnsafeMutablePointer<C>' produces a pointer valid only for the duration of the call to 'init(_:)'}}
12+
13+
_ = AutoreleasingUnsafeMutablePointer<AnyObject>(&c) // expected-warning {{initialization of 'AutoreleasingUnsafeMutablePointer<AnyObject>' results in a dangling pointer}}
14+
// expected-note@-1 {{implicit argument conversion from 'C' to 'UnsafeMutablePointer<C>' produces a pointer valid only for the duration of the call to 'init(_:)'}}
15+
// expected-note@-2 {{use 'withUnsafeMutablePointer' in order to explicitly convert argument to pointer valid for a defined scope}}
716

8-
_ = AutoreleasingUnsafeMutablePointer(&c) // expected-warning {{initialization of 'AutoreleasingUnsafeMutablePointer<C?>' results in a dangling pointer}}
17+
_ = AutoreleasingUnsafeMutablePointer(&optC) // expected-warning {{initialization of 'AutoreleasingUnsafeMutablePointer<C?>' results in a dangling pointer}}
918
// expected-note@-1 {{implicit argument conversion from 'C?' to 'AutoreleasingUnsafeMutablePointer<C?>' produces a pointer valid only for the duration of the call to 'init(_:)'}}
19+
20+
_ = AutoreleasingUnsafeMutablePointer<C>(&optC) // expected-warning {{initialization of 'AutoreleasingUnsafeMutablePointer<C>' results in a dangling pointer}}
21+
// expected-note@-1 {{implicit argument conversion from 'C?' to 'UnsafeMutablePointer<C?>' produces a pointer valid only for the duration of the call to 'init(_:)'}}
22+
// expected-note@-2 {{use 'withUnsafeMutablePointer' in order to explicitly convert argument to pointer valid for a defined scope}}
23+
24+
_ = AutoreleasingUnsafeMutablePointer<AnyObject>(&optC) // expected-warning {{initialization of 'AutoreleasingUnsafeMutablePointer<AnyObject>' results in a dangling pointer}}
25+
// expected-note@-1 {{implicit argument conversion from 'C?' to 'UnsafeMutablePointer<C?>' produces a pointer valid only for the duration of the call to 'init(_:)'}}
26+
// expected-note@-2 {{use 'withUnsafeMutablePointer' in order to explicitly convert argument to pointer valid for a defined scope}}
27+
28+
_ = AutoreleasingUnsafeMutablePointer<AnyObject?>(&optC) // expected-warning {{initialization of 'AutoreleasingUnsafeMutablePointer<AnyObject?>' results in a dangling pointer}}
29+
// expected-note@-1 {{implicit argument conversion from 'C?' to 'UnsafeMutablePointer<C?>' produces a pointer valid only for the duration of the call to 'init(_:)'}}
30+
// expected-note@-2 {{use 'withUnsafeMutablePointer' in order to explicitly convert argument to pointer valid for a defined scope}}
1031
}

0 commit comments

Comments
 (0)