mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
* Migrate from `UnsafePointer<Void>` to `UnsafeRawPointer`. As proposed in SE-0107: UnsafeRawPointer. `void*` imports as `UnsafeMutableRawPointer`. `const void*` imports as `UnsafeRawPointer`. Occurrences of `UnsafePointer<Void>` are replaced with UnsafeRawPointer. * Migrate overlays from UnsafePointer<Void> to UnsafeRawPointer. This requires explicit memory binding in several places, particularly in NSData and CoreAudio. * Fix a bunch of test cases for Void->Raw migration. * qsort takes IUO values * Bridge `Unsafe[Mutable]RawPointer as `void [const] *`. * Parse #dsohandle as UnsafeMutableRawPointer * Update a bunch of test cases for Void->Raw migration. * Trivial fix for the SceneKit test case. * Add an UnsafeRawPointer self initializer. This is unfortunately necessary for assignment between types imported from C. * Tiny simplification of the initializer.
72 lines
3.5 KiB
Plaintext
72 lines
3.5 KiB
Plaintext
// RUN: rm -rf %t && mkdir -p %t
|
|
|
|
// RUN: %gyb -DOPT_KIND=None %s -o %t/pointer_conversion.swift
|
|
// RUN: %line-directive %t/pointer_conversion.swift -- %target-swift-frontend -parse -verify %t/pointer_conversion.swift
|
|
|
|
// RUN: %gyb -DOPT_KIND=Optional %s -o %t/pointer_conversion_opt.swift
|
|
// RUN: %line-directive %t/pointer_conversion_opt.swift -- %target-swift-frontend -parse -verify %t/pointer_conversion_opt.swift
|
|
|
|
// RUN: %gyb -DOPT_KIND=ImplicitlyUnwrappedOptional %s -o %t/pointer_conversion_iuo.swift
|
|
// RUN: %line-directive %t/pointer_conversion_iuo.swift -- %target-swift-frontend -parse -verify %t/pointer_conversion_iuo.swift
|
|
|
|
// REQUIRES: objc_interop
|
|
|
|
%{
|
|
if OPT_KIND == 'Optional':
|
|
suffix='?'
|
|
elif OPT_KIND == 'ImplicitlyUnwrappedOptional':
|
|
suffix='!'
|
|
else:
|
|
suffix=''
|
|
}%
|
|
|
|
class C {}
|
|
class D {}
|
|
|
|
func takesMutablePointer(_ x: UnsafeMutablePointer<Int>${suffix}) {}
|
|
func takesMutableVoidPointer(_ x: UnsafeMutableRawPointer${suffix}) {}
|
|
@discardableResult
|
|
func takesConstPointer(_ x: UnsafePointer<Int>${suffix}) -> Character { return "x" }
|
|
func takesConstVoidPointer(_ x: UnsafeRawPointer${suffix}) {}
|
|
|
|
func takesAutoreleasingPointer(_ x: AutoreleasingUnsafeMutablePointer<C>${suffix}) {}
|
|
|
|
func pointerArgumentsObjC(ap: AutoreleasingUnsafeMutablePointer<Int>,
|
|
afp: AutoreleasingUnsafeMutablePointer<Float>) {
|
|
takesMutablePointer(ap) // expected-error{{cannot convert value of type 'AutoreleasingUnsafeMutablePointer<Int>' to expected argument type 'UnsafeMutablePointer<Int>${suffix}'}}
|
|
takesMutableVoidPointer(ap) // expected-error{{cannot convert value of type 'AutoreleasingUnsafeMutablePointer<Int>' to expected argument type 'UnsafeMutableRawPointer${suffix}'}}
|
|
takesConstPointer(ap)
|
|
takesConstVoidPointer(ap)
|
|
takesConstVoidPointer(afp)
|
|
|
|
var x: UnsafeRawPointer
|
|
x = ap // expected-error{{cannot assign value of type 'AutoreleasingUnsafeMutablePointer<Int>' to type 'UnsafeRawPointer'}}
|
|
_ = x
|
|
}
|
|
|
|
func autoreleasingPointerArguments(p: UnsafeMutablePointer<Int>,
|
|
cp: UnsafePointer<Int>,
|
|
ap: AutoreleasingUnsafeMutablePointer<C>) {
|
|
takesAutoreleasingPointer(nil)
|
|
% if not suffix:
|
|
// expected-error@-2 {{nil is not compatible with expected argument type}}
|
|
% end
|
|
|
|
takesAutoreleasingPointer(p) // expected-error{{cannot convert value of type 'UnsafeMutablePointer<Int>' to expected argument type 'AutoreleasingUnsafeMutablePointer<C>${suffix}'}}
|
|
takesAutoreleasingPointer(cp) // expected-error{{cannot convert value of type 'UnsafePointer<Int>' to expected argument type 'AutoreleasingUnsafeMutablePointer<C>${suffix}'}}
|
|
takesAutoreleasingPointer(ap)
|
|
|
|
var c: C = C()
|
|
takesAutoreleasingPointer(&c)
|
|
takesAutoreleasingPointer(c) // expected-error{{cannot convert value of type 'C' to expected argument type 'AutoreleasingUnsafeMutablePointer<C>${suffix}'}}
|
|
var d: D = D()
|
|
takesAutoreleasingPointer(&d) // expected-error{{cannot convert value of type 'D' to expected argument type 'C'}}
|
|
takesAutoreleasingPointer(d) // expected-error{{cannot convert value of type 'D' to expected argument type 'AutoreleasingUnsafeMutablePointer<C>${suffix}'}}
|
|
var cc: [C] = [C(), C()]
|
|
var dd: [D] = [D(), D()]
|
|
takesAutoreleasingPointer(&cc) // expected-error{{cannot convert value of type '[C]' to expected argument type 'C'}}
|
|
takesAutoreleasingPointer(&dd) // expected-error{{cannot convert value of type '[D]' to expected argument type 'C'}}
|
|
|
|
let _: AutoreleasingUnsafeMutablePointer<C> = &c // expected-error{{cannot pass immutable value of type 'C' as inout argument}}
|
|
}
|