Skip to content

Instantly share code, notes, and snippets.

@623637646
Last active November 21, 2019 08:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 623637646/c0ed7c8d5a712cae7c3f44e6f644e139 to your computer and use it in GitHub Desktop.
Save 623637646/c0ed7c8d5a712cae7c3f44e6f644e139 to your computer and use it in GitHub Desktop.
A bug of AutoreleasingUnsafeMutablePointer compiling
import UIKit
class ViewController: UIViewController {
struct OneStruct {
}
class OneClass {
}
override func viewDidLoad() {
super.viewDidLoad()
// compile failed
var oneStruct: OneStruct?
test(&oneStruct)
assert(oneStruct != nil)
// compile success and run success
// var oneClass: OneClass?
// test2(&oneClass)
// assert(oneClass != nil)
}
func test(_ p: AutoreleasingUnsafeMutablePointer<OneStruct?>) {
p.pointee = OneStruct()
}
func test2(_ p: AutoreleasingUnsafeMutablePointer<OneClass?>) {
p.pointee = OneClass()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment