Typedef const reference from a pointer
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/5924248/why-is-it-allowed-to-cast-a-pointer-to-a-reference">Why is it allowed to cast a pointer to a reference?</a>  </p>
</blockquote>



<p>Why does this compile:</p>

<pre><code>class Bar {};

int main() {
  Bar i;
  Bar *b = &amp;i;
  typedef const Bar&amp; type;
  type t = type(b);
}
</code></pre>

<p>G++ (<a href="http://www.ideone.com/huvDG" rel="nofollow">4.5</a>, 4.7 snapshots), <a href="http://www.comeaucomputing.com/tryitout/" rel="nofollow">Comeau</a> and MSVC all are happy but warn about unused variables.</p>

<p>What does the compiler think it means? Is it UB? Why isn't it an error?</p>

<p>I think it should be an error because I've accidentally made a <code>Bar*</code> into <code>const Bar&amp;</code> without dereferencing or crazy casts. I thought every part of this was completely safe.</p>
