|
1 | 1 | // RUN: %target-typecheck-verify-swift -enable-invalid-ephemeralness-as-error
|
2 | 2 | // REQUIRES: objc_interop
|
3 | 3 |
|
| 4 | +class C {} |
| 5 | + |
4 | 6 | 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}} |
7 | 16 |
|
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}} |
9 | 18 | // 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}} |
10 | 31 | }
|
0 commit comments