// RUN: %target-typecheck-verify-swift -enable-invalid-ephemeralness-as-error -disable-objc-interop // Test availability attributes on UnsafePointer initializers. // Assume the original source contains no UnsafeRawPointer types. func unsafePointerConversionAvailability( mrp: UnsafeMutableRawPointer, rp: UnsafeRawPointer, umpv: UnsafeMutablePointer, // expected-warning {{UnsafeMutablePointer has been replaced by UnsafeMutableRawPointer}} upv: UnsafePointer, // expected-warning {{UnsafePointer has been replaced by UnsafeRawPointer}} umpi: UnsafeMutablePointer, upi: UnsafePointer, umps: UnsafeMutablePointer, ups: UnsafePointer) { let omrp: UnsafeMutableRawPointer? = mrp let orp: UnsafeRawPointer? = rp let oumpv: UnsafeMutablePointer = umpv // expected-warning {{UnsafeMutablePointer has been replaced by UnsafeMutableRawPointer}} let oupv: UnsafePointer? = upv // expected-warning {{UnsafePointer has been replaced by UnsafeRawPointer}} let oumpi: UnsafeMutablePointer? = umpi let oupi: UnsafePointer? = upi let oumps: UnsafeMutablePointer? = umps let oups: UnsafePointer? = ups _ = UnsafeMutableRawPointer(mrp) _ = UnsafeMutableRawPointer(rp) // expected-error {{'init(_:)' has been renamed to 'init(mutating:)'}} _ = UnsafeMutableRawPointer(umpv) _ = UnsafeMutableRawPointer(upv) // expected-error {{'init(_:)' has been renamed to 'init(mutating:)'}} _ = UnsafeMutableRawPointer(umpi) _ = UnsafeMutableRawPointer(upi) // expected-error {{'init(_:)' has been renamed to 'init(mutating:)'}} _ = UnsafeMutableRawPointer(umps) _ = UnsafeMutableRawPointer(ups) // expected-error {{'init(_:)' has been renamed to 'init(mutating:)'}} _ = UnsafeMutableRawPointer(omrp) _ = UnsafeMutableRawPointer(orp) // expected-error {{'init(_:)' has been renamed to 'init(mutating:)'}} _ = UnsafeMutableRawPointer(oumpv) _ = UnsafeMutableRawPointer(oupv) // expected-error {{'init(_:)' has been renamed to 'init(mutating:)'}} _ = UnsafeMutableRawPointer(oumpi) _ = UnsafeMutableRawPointer(oupi) // expected-error {{'init(_:)' has been renamed to 'init(mutating:)'}} _ = UnsafeMutableRawPointer(oumps) _ = UnsafeMutableRawPointer(oups) // expected-error {{'init(_:)' has been renamed to 'init(mutating:)'}} // These all correctly pass with no error. _ = UnsafeRawPointer(mrp) _ = UnsafeRawPointer(rp) _ = UnsafeRawPointer(umpv) _ = UnsafeRawPointer(upv) _ = UnsafeRawPointer(umpi) _ = UnsafeRawPointer(upi) _ = UnsafeRawPointer(umps) _ = UnsafeRawPointer(ups) _ = UnsafeRawPointer(omrp) _ = UnsafeRawPointer(orp) _ = UnsafeRawPointer(oumpv) _ = UnsafeRawPointer(oupv) _ = UnsafeRawPointer(oumpi) _ = UnsafeRawPointer(oupi) _ = UnsafeRawPointer(oumps) _ = UnsafeRawPointer(oups) _ = UnsafePointer(upi) _ = UnsafePointer(oumpi) _ = UnsafePointer(oupi) _ = UnsafeMutablePointer(umpi) _ = UnsafeMutablePointer(oumpi) _ = UnsafeMutablePointer(rp) // expected-error {{no exact matches in call to initializer}} expected-warning {{UnsafeMutablePointer has been replaced by UnsafeMutableRawPointer}} _ = UnsafeMutablePointer(mrp) // expected-error {{no exact matches in call to initializer}} expected-warning {{UnsafeMutablePointer has been replaced by UnsafeMutableRawPointer}} _ = UnsafeMutablePointer(umpv) // expected-warning {{UnsafeMutablePointer has been replaced by UnsafeMutableRawPointer}} _ = UnsafeMutablePointer(umpi) // expected-warning {{UnsafeMutablePointer has been replaced by UnsafeMutableRawPointer}} _ = UnsafeMutablePointer(umps) // expected-warning {{UnsafeMutablePointer has been replaced by UnsafeMutableRawPointer}} _ = UnsafePointer(rp) // expected-error {{no exact matches in call to initializer}} expected-warning {{UnsafePointer has been replaced by UnsafeRawPointer}} _ = UnsafePointer(mrp) // expected-error {{no exact matches in call to initializer}} expected-warning {{UnsafePointer has been replaced by UnsafeRawPointer}} _ = UnsafePointer(umpv) // expected-warning {{UnsafePointer has been replaced by UnsafeRawPointer}} _ = UnsafePointer(upv) // expected-warning {{UnsafePointer has been replaced by UnsafeRawPointer}} _ = UnsafePointer(umpi) // expected-warning {{UnsafePointer has been replaced by UnsafeRawPointer}} _ = UnsafePointer(upi) // expected-warning {{UnsafePointer has been replaced by UnsafeRawPointer}} _ = UnsafePointer(umps) // expected-warning {{UnsafePointer has been replaced by UnsafeRawPointer}} _ = UnsafePointer(ups) // expected-warning {{UnsafePointer has been replaced by UnsafeRawPointer}} _ = UnsafeMutablePointer(rp) // expected-error {{no exact matches in call to initializer}} _ = UnsafeMutablePointer(mrp) // expected-error {{no exact matches in call to initializer}} _ = UnsafeMutablePointer(orp) // expected-error {{no exact matches in call to initializer}} _ = UnsafeMutablePointer(omrp) // expected-error {{no exact matches in call to initializer}} _ = UnsafePointer(rp) // expected-error {{no exact matches in call to initializer}} _ = UnsafePointer(mrp) // expected-error {{no exact matches in call to initializer}} _ = UnsafePointer(orp) // expected-error {{no exact matches in call to initializer}} _ = UnsafePointer(omrp) // expected-error {{no exact matches in call to initializer}} _ = UnsafePointer(ups) // expected-error {{cannot convert value of type 'UnsafePointer' to expected argument type 'UnsafePointer'}} // expected-note@-1 {{arguments to generic parameter 'Pointee' ('String' and 'Int') are expected to be equal}} _ = UnsafeMutablePointer(umps) // expected-error {{cannot convert value of type 'UnsafeMutablePointer' to expected argument type 'UnsafeMutablePointer'}} // expected-note@-1 {{arguments to generic parameter 'Pointee' ('String' and 'Int') are expected to be equal}} _ = UnsafePointer(upi) // expected-error {{cannot convert value of type 'UnsafePointer' to expected argument type 'UnsafePointer'}} // expected-note@-1 {{arguments to generic parameter 'Pointee' ('Int' and 'String') are expected to be equal}} _ = UnsafeMutablePointer(umpi) // expected-error {{cannot convert value of type 'UnsafeMutablePointer' to expected argument type 'UnsafeMutablePointer'}} // expected-note@-1 {{arguments to generic parameter 'Pointee' ('Int' and 'String') are expected to be equal}} } func unsafeRawBufferPointerConversions( mrp: UnsafeMutableRawPointer, rp: UnsafeRawPointer, mrbp: UnsafeMutableRawBufferPointer, rbp: UnsafeRawBufferPointer, mbpi: UnsafeMutableBufferPointer, bpi: UnsafeBufferPointer) { let omrp: UnsafeMutableRawPointer? = mrp let orp: UnsafeRawPointer? = rp _ = UnsafeMutableRawBufferPointer(start: mrp, count: 1) _ = UnsafeRawBufferPointer(start: mrp, count: 1) _ = UnsafeMutableRawBufferPointer(start: rp, count: 1) // expected-error {{cannot convert value of type 'UnsafeRawPointer' to expected argument type 'UnsafeMutableRawPointer?'}} _ = UnsafeRawBufferPointer(start: rp, count: 1) _ = UnsafeMutableRawBufferPointer(mrbp) _ = UnsafeRawBufferPointer(mrbp) _ = UnsafeMutableRawBufferPointer(rbp) // expected-error {{missing argument label 'mutating:' in call}} _ = UnsafeRawBufferPointer(rbp) _ = UnsafeMutableRawBufferPointer(mbpi) _ = UnsafeRawBufferPointer(mbpi) _ = UnsafeMutableRawBufferPointer(bpi) // expected-error {{cannot convert value of type 'UnsafeBufferPointer' to expected argument type 'UnsafeMutableRawBufferPointer'}} _ = UnsafeRawBufferPointer(bpi) _ = UnsafeMutableRawBufferPointer(start: omrp, count: 1) _ = UnsafeRawBufferPointer(start: omrp, count: 1) _ = UnsafeMutableRawBufferPointer(start: orp, count: 1) // expected-error {{cannot convert value of type 'UnsafeRawPointer?' to expected argument type 'UnsafeMutableRawPointer?'}} _ = UnsafeRawBufferPointer(start: orp, count: 1) } struct SR9800 { func foo(_: UnsafePointer) {} func foo(_: UnsafePointer) {} func ambiguityTest(buf: UnsafeMutablePointer) { foo(UnsafePointer(buf)) // this call should be unambiguoius } } // Test that we get a custom diagnostic for an ephemeral conversion to non-ephemeral param for an Unsafe[Mutable][Raw][Buffer]Pointer init. func unsafePointerInitEphemeralConversions() { class C {} var foo = 0 var str = "" var arr = [0] var optionalArr: [Int]? = [0] var c: C? _ = UnsafePointer(&foo) // expected-error {{initialization of 'UnsafePointer' results in a dangling pointer}} // expected-note@-1 {{implicit argument conversion from 'Int' to 'UnsafePointer' produces a pointer valid only for the duration of the call to 'init(_:)'}} // expected-note@-2 {{use 'withUnsafePointer' in order to explicitly convert argument to pointer valid for a defined scope}} _ = UnsafePointer(&foo + 1) // expected-error {{cannot use inout expression here; argument #1 must be a pointer that outlives the call to '+'}} // expected-note@-1 {{implicit argument conversion from 'Int' to 'UnsafePointer' produces a pointer valid only for the duration of the call to '+'}} // expected-note@-2 {{use 'withUnsafePointer' in order to explicitly convert argument to pointer valid for a defined scope}} _ = UnsafePointer.init(&foo) // expected-error {{initialization of 'UnsafePointer' results in a dangling pointer}} // expected-note@-1 {{implicit argument conversion from 'Int' to 'UnsafePointer' produces a pointer valid only for the duration of the call to 'init(_:)'}} // expected-note@-2 {{use 'withUnsafePointer' in order to explicitly convert argument to pointer valid for a defined scope}} _ = UnsafePointer("") // expected-error {{initialization of 'UnsafePointer' results in a dangling pointer}} // expected-note@-1 {{implicit argument conversion from 'String' to 'UnsafePointer' produces a pointer valid only for the duration of the call to 'init(_:)'}} // expected-note@-2 {{use the 'withCString' method on String in order to explicitly convert argument to pointer valid for a defined scope}} _ = UnsafePointer.init("") // expected-error {{initialization of 'UnsafePointer' results in a dangling pointer}} // expected-note@-1 {{implicit argument conversion from 'String' to 'UnsafePointer' produces a pointer valid only for the duration of the call to 'init(_:)'}} // expected-note@-2 {{use the 'withCString' method on String in order to explicitly convert argument to pointer valid for a defined scope}} _ = UnsafePointer(str) // expected-error {{initialization of 'UnsafePointer' results in a dangling pointer}} // expected-note@-1 {{implicit argument conversion from 'String' to 'UnsafePointer' produces a pointer valid only for the duration of the call to 'init(_:)'}} // expected-note@-2 {{use the 'withCString' method on String in order to explicitly convert argument to pointer valid for a defined scope}} _ = UnsafePointer([0]) // expected-error {{initialization of 'UnsafePointer' results in a dangling pointer}} // expected-note@-1 {{implicit argument conversion from '[Int]' to 'UnsafePointer' produces a pointer valid only for the duration of the call to 'init(_:)'}} // expected-note@-2 {{use the 'withUnsafeBufferPointer' method on Array in order to explicitly convert argument to buffer pointer valid for a defined scope}} _ = UnsafePointer(arr) // expected-error {{initialization of 'UnsafePointer' results in a dangling pointer}} // expected-note@-1 {{implicit argument conversion from '[Int]' to 'UnsafePointer' produces a pointer valid only for the duration of the call to 'init(_:)'}} // expected-note@-2 {{use the 'withUnsafeBufferPointer' method on Array in order to explicitly convert argument to buffer pointer valid for a defined scope}} _ = UnsafePointer(&arr) // expected-error {{initialization of 'UnsafePointer' results in a dangling pointer}} // expected-note@-1 {{implicit argument conversion from '[Int]' to 'UnsafePointer' produces a pointer valid only for the duration of the call to 'init(_:)'}} // expected-note@-2 {{use the 'withUnsafeBufferPointer' method on Array in order to explicitly convert argument to buffer pointer valid for a defined scope}} _ = UnsafePointer(optionalArr) // expected-error {{initialization of 'UnsafePointer' results in a dangling pointer}} // expected-note@-1 {{implicit argument conversion from '[Int]?' to 'UnsafePointer?' produces a pointer valid only for the duration of the call to 'init(_:)'}} _ = UnsafeMutablePointer(&foo) // expected-error {{initialization of 'UnsafeMutablePointer' results in a dangling pointer}} // expected-note@-1 {{implicit argument conversion from 'Int' to 'UnsafeMutablePointer' produces a pointer valid only for the duration of the call to 'init(_:)'}} // expected-note@-2 {{use 'withUnsafeMutablePointer' in order to explicitly convert argument to pointer valid for a defined scope}} _ = UnsafeMutablePointer(&arr) // expected-error {{initialization of 'UnsafeMutablePointer' results in a dangling pointer}} // expected-note@-1 {{implicit argument conversion from '[Int]' to 'UnsafeMutablePointer' produces a pointer valid only for the duration of the call to 'init(_:)'}} // expected-note@-2 {{use the 'withUnsafeMutableBufferPointer' method on Array in order to explicitly convert argument to buffer pointer valid for a defined scope}} _ = UnsafeMutablePointer(&arr + 2) // expected-error {{cannot use inout expression here; argument #1 must be a pointer that outlives the call to '+'}} // expected-note@-1 {{implicit argument conversion from '[Int]' to 'UnsafeMutablePointer' produces a pointer valid only for the duration of the call to '+'}} // expected-note@-2 {{use the 'withUnsafeMutableBufferPointer' method on Array in order to explicitly convert argument to buffer pointer valid for a defined scope}} _ = UnsafeMutablePointer(mutating: &foo) // expected-error {{initialization of 'UnsafeMutablePointer' results in a dangling pointer}} // expected-note@-1 {{implicit argument conversion from 'Int' to 'UnsafePointer' produces a pointer valid only for the duration of the call to 'init(mutating:)}} // expected-note@-2 {{use 'withUnsafePointer' in order to explicitly convert argument to pointer valid for a defined scope}} _ = UnsafeMutablePointer(mutating: "") // expected-error {{initialization of 'UnsafeMutablePointer' results in a dangling pointer}} // expected-note@-1 {{implicit argument conversion from 'String' to 'UnsafePointer' produces a pointer valid only for the duration of the call to 'init(mutating:)}} // expected-note@-2 {{use the 'withCString' method on String in order to explicitly convert argument to pointer valid for a defined scope}} _ = UnsafeMutablePointer(mutating: str) // expected-error {{initialization of 'UnsafeMutablePointer' results in a dangling pointer}} // expected-note@-1 {{implicit argument conversion from 'String' to 'UnsafePointer' produces a pointer valid only for the duration of the call to 'init(mutating:)}} // expected-note@-2 {{use the 'withCString' method on String in order to explicitly convert argument to pointer valid for a defined scope}} _ = UnsafeMutablePointer(mutating: [0]) // expected-error {{initialization of 'UnsafeMutablePointer' results in a dangling pointer}} // expected-note@-1 {{implicit argument conversion from '[Int]' to 'UnsafePointer' produces a pointer valid only for the duration of the call to 'init(mutating:)}} // expected-note@-2 {{use the 'withUnsafeBufferPointer' method on Array in order to explicitly convert argument to buffer pointer valid for a defined scope}} _ = UnsafeMutablePointer(mutating: arr) // expected-error {{initialization of 'UnsafeMutablePointer' results in a dangling pointer}} // expected-note@-1 {{implicit argument conversion from '[Int]' to 'UnsafePointer' produces a pointer valid only for the duration of the call to 'init(mutating:)}} // expected-note@-2 {{use the 'withUnsafeBufferPointer' method on Array in order to explicitly convert argument to buffer pointer valid for a defined scope}} _ = UnsafeMutablePointer(mutating: &arr) // expected-error {{initialization of 'UnsafeMutablePointer' results in a dangling pointer}} // expected-note@-1 {{implicit argument conversion from '[Int]' to 'UnsafePointer' produces a pointer valid only for the duration of the call to 'init(mutating:)}} // expected-note@-2 {{use the 'withUnsafeBufferPointer' method on Array in order to explicitly convert argument to buffer pointer valid for a defined scope}} _ = UnsafeMutablePointer(mutating: optionalArr) // expected-error {{initialization of 'UnsafeMutablePointer' results in a dangling pointer}} // expected-note@-1 {{implicit argument conversion from '[Int]?' to 'UnsafePointer?' produces a pointer valid only for the duration of the call to 'init(mutating:)}} _ = UnsafeRawPointer(&foo) // expected-error {{initialization of 'UnsafeRawPointer' results in a dangling pointer}} // expected-note@-1 {{implicit argument conversion from 'Int' to 'UnsafeMutableRawPointer' produces a pointer valid only for the duration of the call to 'init(_:)'}} // expected-note@-2 {{use 'withUnsafeMutableBytes' in order to explicitly convert argument to buffer pointer valid for a defined scope}} _ = UnsafeRawPointer(str) // expected-error {{initialization of 'UnsafeRawPointer' results in a dangling pointer}} // expected-note@-1 {{implicit argument conversion from 'String' to 'UnsafeRawPointer' produces a pointer valid only for the duration of the call to 'init(_:)'}} // expected-note@-2 {{use the 'withCString' method on String in order to explicitly convert argument to pointer valid for a defined scope}} _ = UnsafeRawPointer(arr) // expected-error {{initialization of 'UnsafeRawPointer' results in a dangling pointer}} // expected-note@-1 {{implicit argument conversion from '[Int]' to 'UnsafeRawPointer' produces a pointer valid only for the duration of the call to 'init(_:)'}} // expected-note@-2 {{use the 'withUnsafeBytes' method on Array in order to explicitly convert argument to buffer pointer valid for a defined scope}} _ = UnsafeRawPointer(&arr) // expected-error {{initialization of 'UnsafeRawPointer' results in a dangling pointer}} // expected-note@-1 {{implicit argument conversion from '[Int]' to 'UnsafeMutableRawPointer' produces a pointer valid only for the duration of the call to 'init(_:)'}} // expected-note@-2 {{use the 'withUnsafeMutableBytes' method on Array in order to explicitly convert argument to buffer pointer valid for a defined scope}} _ = UnsafeRawPointer(optionalArr) // expected-error {{initialization of 'UnsafeRawPointer' results in a dangling pointer}} // expected-note@-1 {{implicit argument conversion from '[Int]?' to 'UnsafeRawPointer?' produces a pointer valid only for the duration of the call to 'init(_:)'}} _ = UnsafeMutableRawPointer(&foo) // expected-error {{initialization of 'UnsafeMutableRawPointer' results in a dangling pointer}} // expected-note@-1 {{implicit argument conversion from 'Int' to 'UnsafeMutableRawPointer' produces a pointer valid only for the duration of the call to 'init(_:)'}} // expected-note@-2 {{use 'withUnsafeMutableBytes' in order to explicitly convert argument to buffer pointer valid for a defined scope}} _ = UnsafeMutableRawPointer(&arr) // expected-error {{initialization of 'UnsafeMutableRawPointer' results in a dangling pointer}} // expected-note@-1 {{implicit argument conversion from '[Int]' to 'UnsafeMutableRawPointer' produces a pointer valid only for the duration of the call to 'init(_:)'}} // expected-note@-2 {{use the 'withUnsafeMutableBytes' method on Array in order to explicitly convert argument to buffer pointer valid for a defined scope}} _ = UnsafeMutableRawPointer(mutating: &foo) // expected-error {{initialization of 'UnsafeMutableRawPointer' results in a dangling pointer}} // expected-note@-1 {{implicit argument conversion from 'Int' to 'UnsafeRawPointer' produces a pointer valid only for the duration of the call to 'init(mutating:)}} // expected-note@-2 {{use 'withUnsafeBytes' in order to explicitly convert argument to buffer pointer valid for a defined scope}} _ = UnsafeMutableRawPointer(mutating: str) // expected-error {{initialization of 'UnsafeMutableRawPointer' results in a dangling pointer}} // expected-note@-1 {{implicit argument conversion from 'String' to 'UnsafeRawPointer' produces a pointer valid only for the duration of the call to 'init(mutating:)}} // expected-note@-2 {{use the 'withCString' method on String in order to explicitly convert argument to pointer valid for a defined scope}} _ = UnsafeMutableRawPointer(mutating: arr) // expected-error {{initialization of 'UnsafeMutableRawPointer' results in a dangling pointer}} // expected-note@-1 {{implicit argument conversion from '[Int]' to 'UnsafeRawPointer' produces a pointer valid only for the duration of the call to 'init(mutating:)}} // expected-note@-2 {{use the 'withUnsafeBytes' method on Array in order to explicitly convert argument to buffer pointer valid for a defined scope}} _ = UnsafeMutableRawPointer(mutating: &arr) // expected-error {{initialization of 'UnsafeMutableRawPointer' results in a dangling pointer}} // expected-note@-1 {{implicit argument conversion from '[Int]' to 'UnsafeRawPointer' produces a pointer valid only for the duration of the call to 'init(mutating:)}} // expected-note@-2 {{use the 'withUnsafeBytes' method on Array in order to explicitly convert argument to buffer pointer valid for a defined scope}} _ = UnsafeMutableRawPointer(mutating: optionalArr) // expected-error {{initialization of 'UnsafeMutableRawPointer' results in a dangling pointer}} // expected-note@-1 {{implicit argument conversion from '[Int]?' to 'UnsafeRawPointer?' produces a pointer valid only for the duration of the call to 'init(mutating:)}} _ = UnsafeBufferPointer(start: &foo, count: 0) // expected-error {{initialization of 'UnsafeBufferPointer' results in a dangling buffer pointer}} // expected-note@-1 {{implicit argument conversion from 'Int' to 'UnsafePointer?' produces a pointer valid only for the duration of the call to 'init(start:count:)'}} // expected-note@-2 {{use 'withUnsafePointer' in order to explicitly convert argument to pointer valid for a defined scope}} _ = UnsafeBufferPointer.init(start: &foo, count: 0) // expected-error {{initialization of 'UnsafeBufferPointer' results in a dangling buffer pointer}} // expected-note@-1 {{implicit argument conversion from 'Int' to 'UnsafePointer?' produces a pointer valid only for the duration of the call to 'init(start:count:)'}} // expected-note@-2 {{use 'withUnsafePointer' in order to explicitly convert argument to pointer valid for a defined scope}} _ = UnsafeBufferPointer(start: str, count: 0) // expected-error {{initialization of 'UnsafeBufferPointer' results in a dangling buffer pointer}} // expected-note@-1 {{implicit argument conversion from 'String' to 'UnsafePointer?' produces a pointer valid only for the duration of the call to 'init(start:count:)'}} // expected-note@-2 {{use the 'withCString' method on String in order to explicitly convert argument to pointer valid for a defined scope}} _ = UnsafeBufferPointer.init(start: str, count: 0) // expected-error {{initialization of 'UnsafeBufferPointer' results in a dangling buffer pointer}} // expected-note@-1 {{implicit argument conversion from 'String' to 'UnsafePointer?' produces a pointer valid only for the duration of the call to 'init(start:count:)'}} // expected-note@-2 {{use the 'withCString' method on String in order to explicitly convert argument to pointer valid for a defined scope}} _ = UnsafeBufferPointer(start: arr, count: 0) // expected-error {{initialization of 'UnsafeBufferPointer' results in a dangling buffer pointer}} // expected-note@-1 {{implicit argument conversion from '[Int]' to 'UnsafePointer?' produces a pointer valid only for the duration of the call to 'init(start:count:)'}} // expected-note@-2 {{use the 'withUnsafeBufferPointer' method on Array in order to explicitly convert argument to buffer pointer valid for a defined scope}} _ = UnsafeBufferPointer(start: &arr, count: 0) // expected-error {{initialization of 'UnsafeBufferPointer' results in a dangling buffer pointer}} // expected-note@-1 {{implicit argument conversion from '[Int]' to 'UnsafePointer?' produces a pointer valid only for the duration of the call to 'init(start:count:)'}} // expected-note@-2 {{use the 'withUnsafeBufferPointer' method on Array in order to explicitly convert argument to buffer pointer valid for a defined scope}} _ = UnsafeBufferPointer(start: optionalArr, count: 0) // expected-error {{initialization of 'UnsafeBufferPointer' results in a dangling buffer pointer}} // expected-note@-1 {{implicit argument conversion from '[Int]?' to 'UnsafePointer?' produces a pointer valid only for the duration of the call to 'init(start:count:)'}} _ = UnsafeMutableBufferPointer(start: &foo, count: 0) // expected-error {{initialization of 'UnsafeMutableBufferPointer' results in a dangling buffer pointer}} // expected-note@-1 {{implicit argument conversion from 'Int' to 'UnsafeMutablePointer?' produces a pointer valid only for the duration of the call to 'init(start:count:)'}} // expected-note@-2 {{use 'withUnsafeMutablePointer' in order to explicitly convert argument to pointer valid for a defined scope}} _ = UnsafeMutableBufferPointer(start: &arr, count: 0) // expected-error {{initialization of 'UnsafeMutableBufferPointer' results in a dangling buffer pointer}} // expected-note@-1 {{implicit argument conversion from '[Int]' to 'UnsafeMutablePointer?' produces a pointer valid only for the duration of the call to 'init(start:count:)'}} // expected-note@-2 {{use the 'withUnsafeMutableBufferPointer' method on Array in order to explicitly convert argument to buffer pointer valid for a defined scope}} _ = UnsafeRawBufferPointer(start: &foo, count: 0) // expected-error {{initialization of 'UnsafeRawBufferPointer' results in a dangling buffer pointer}} // expected-note@-1 {{implicit argument conversion from 'Int' to 'UnsafeRawPointer?' produces a pointer valid only for the duration of the call to 'init(start:count:)'}} // expected-note@-2 {{use 'withUnsafeBytes' in order to explicitly convert argument to buffer pointer valid for a defined scope}} _ = UnsafeRawBufferPointer(start: str, count: 0) // expected-error {{initialization of 'UnsafeRawBufferPointer' results in a dangling buffer pointer}} // expected-note@-1 {{implicit argument conversion from 'String' to 'UnsafeRawPointer?' produces a pointer valid only for the duration of the call to 'init(start:count:)'}} // expected-note@-2 {{use the 'withCString' method on String in order to explicitly convert argument to pointer valid for a defined scope}} _ = UnsafeRawBufferPointer(start: arr, count: 0) // expected-error {{initialization of 'UnsafeRawBufferPointer' results in a dangling buffer pointer}} // expected-note@-1 {{implicit argument conversion from '[Int]' to 'UnsafeRawPointer?' produces a pointer valid only for the duration of the call to 'init(start:count:)'}} // expected-note@-2 {{use the 'withUnsafeBytes' method on Array in order to explicitly convert argument to buffer pointer valid for a defined scope}} _ = UnsafeRawBufferPointer(start: &arr, count: 0) // expected-error {{initialization of 'UnsafeRawBufferPointer' results in a dangling buffer pointer}} // expected-note@-1 {{implicit argument conversion from '[Int]' to 'UnsafeRawPointer?' produces a pointer valid only for the duration of the call to 'init(start:count:)'}} // expected-note@-2 {{use the 'withUnsafeBytes' method on Array in order to explicitly convert argument to buffer pointer valid for a defined scope}} _ = UnsafeRawBufferPointer(start: optionalArr, count: 0) // expected-error {{initialization of 'UnsafeRawBufferPointer' results in a dangling buffer pointer}} // expected-note@-1 {{implicit argument conversion from '[Int]?' to 'UnsafeRawPointer?' produces a pointer valid only for the duration of the call to 'init(start:count:)'}} _ = UnsafeMutableRawBufferPointer(start: &foo, count: 0) // expected-error {{initialization of 'UnsafeMutableRawBufferPointer' results in a dangling buffer pointer}} // expected-note@-1 {{implicit argument conversion from 'Int' to 'UnsafeMutableRawPointer?' produces a pointer valid only for the duration of the call to 'init(start:count:)'}} // expected-note@-2 {{use 'withUnsafeMutableBytes' in order to explicitly convert argument to buffer pointer valid for a defined scope}} _ = UnsafeMutableRawBufferPointer(start: &arr, count: 0) // expected-error {{initialization of 'UnsafeMutableRawBufferPointer' results in a dangling buffer pointer}} // expected-note@-1 {{implicit argument conversion from '[Int]' to 'UnsafeMutableRawPointer?' produces a pointer valid only for the duration of the call to 'init(start:count:)'}} // expected-note@-2 {{use the 'withUnsafeMutableBytes' method on Array in order to explicitly convert argument to buffer pointer valid for a defined scope}} // FIXME: This is currently ambiguous. _ = OpaquePointer(&foo) // expected-error {{no exact matches in call to initializer}} // FIXME: This is currently ambiguous. _ = OpaquePointer(&arr) // expected-error {{no exact matches in call to initializer}} _ = OpaquePointer(arr) // expected-error {{initialization of 'OpaquePointer' results in a dangling pointer}} // expected-note@-1 {{implicit argument conversion from '[Int]' to 'UnsafeRawPointer' produces a pointer valid only for the duration of the call to 'init(_:)'}} // expected-note@-2 {{use the 'withUnsafeBytes' method on Array in order to explicitly convert argument to buffer pointer valid for a defined scope}} _ = OpaquePointer(str) // expected-error {{initialization of 'OpaquePointer' results in a dangling pointer}} // expected-note@-1 {{implicit argument conversion from 'String' to 'UnsafeRawPointer' produces a pointer valid only for the duration of the call to 'init(_:)'}} // expected-note@-2 {{use the 'withCString' method on String in order to explicitly convert argument to pointer valid for a defined scope}} } var global = 0 // Test that we allow non-ephemeral conversions, such as inout-to-pointer for globals. func unsafePointerInitNonEphemeralConversions() { _ = UnsafePointer(&global) _ = UnsafeMutablePointer(&global) _ = UnsafeRawPointer(&global) _ = UnsafeMutableRawPointer(&global) _ = UnsafeBufferPointer(start: &global, count: 0) _ = UnsafeMutableBufferPointer(start: &global, count: 0) _ = UnsafeRawBufferPointer(start: &global, count: 0) _ = UnsafeMutableRawBufferPointer(start: &global, count: 0) // FIXME: This is currently ambiguous. _ = OpaquePointer(&global) // expected-error {{ambiguous use of 'init(_:)'}} }