> On May 17, 2017, at 14:53, Guillaume Lessard <[email protected]> > wrote: > > >> On May 17, 2017, at 15:28, Jordan Rose <[email protected]> wrote: >> >> This can come up even without &. It is illegal to use >> UnsafeMutablePointer.init(mutating:) on something that was not a mutable >> pointer to begin with, and the program is not guaranteed to do anything >> sensible if you break that rule. > > “Illegal" or no, if it can be done it will de done. I just think it would be > more sensible to *not* allow taking pointers to non-mutable variables at all.
That's what "unsafe" means. To take one specific use case, there's a big difference between withUnsafeBufferPointer and withUnsafeMutableBufferPointer on an Array: the latter triggers copy-on-write behavior before handing you the pointer. That's not an acceptable price to pay just for pointer access to the contents of the array. (Another possible rule would be to drop UnsafeMutablePointer.init(mutating:), but unfortunately there are too many C APIs out there that don't use 'const'.) Jordan _______________________________________________ swift-evolution mailing list [email protected] https://lists.swift.org/mailman/listinfo/swift-evolution
