<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body><div>On Wed, Dec 16, 2015, at 02:25 PM, Jacob Bandes-Storch via swift-evolution wrote:<br></div>
<blockquote type="cite"><div dir="ltr"><div>Is there a reason that this couldn't be made to work?<br></div>
<div><p><span>&nbsp; &nbsp; let ptr: UnsafePointer&lt;Void&gt; = &amp;x</span><br></p></div>
</div>
</blockquote><div>Yes. That breaks several parts of the language:<br></div>
<div>&nbsp;</div>
<div>1. Swift semantics allow you to use computed properties and stored properties interchangeably. That expression there can't work with computed properties unless Swift silently creates a temporary that lives for the entire scope, which would be surprising behavior.<br></div>
<div>2. Swift also aggressively discards values that are no longer used even if they're still in scope (at least under optimization; it likely keeps them around in debug builds so they can be inspected). But there's no way for Swift to know how long that pointer is going to be used for (it could track that variable itself, but what about derived values?). So any value that's used in that expression would also have to have its lifetime extended for the entire scope, which is surprising behavior.<br></div>
<div>3. The pointer definitely cannot be valid outside of the current scope, but there's nothing in that statement to imply this. withUnsafePointer() taking a scope tells the user that the pointer is only valid for the scope (otherwise it would just return the pointer), and similarly the current &amp;x behavior can only be used as a parameter to a function, which tells the user that it's only valid for the duration of that function call.<br></div>
<div>&nbsp;</div>
<div>-Kevin Ballard</div>
</body>
</html>