<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>On Jun 19, 2013, at 1:45 AM, Pavel Labath <<a href="mailto:labath@google.com">labath@google.com</a>> wrote:</div><blockquote type="cite"><div dir="ltr">On 19 June 2013 01:59, John McCall <span dir="ltr"><<a href="mailto:rjmccall@apple.com" target="_blank">rjmccall@apple.com</a>></span> wrote:<div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; position: static; z-index: auto; ">There's nothing wrong with reinterpret_cast'ing to an arbitrary object pointer type; it doesn't need to be standard-layout. You just have to be careful to not (1) increase the alignment requirements (which we should already warn about with -Wcast-align) or (2) do anything with the type-punned pointer except cast it back eventually (which is pretty hard to reason about).<br>
<br>
And there are known encapsulation idioms which involve temporarily punning a pointer as a pointer to an incomplete type, so I'm not sure this is a terribly valuable warning to pursue even for your specific case.<br>
<br>
Obligatory standards quote:<br>
<br>
C++11 [expr.reinterpret.cast]p7:<br>
An object pointer can be explicitly converted to an object pointer of a different type. When a prvalue v of type “pointer to T1” is converted to the type “pointer to cv T2”, the result is static_cast<cv T2*>(static_cast<cv void*>(v)) if both T1 and T2 are standard-layout types (3.9) and</blockquote>
<div>I've read this paragraph before writing, and this part made me believe that the types need to be standard layout. I'm not very good at standardese, so I wasn't sure if this restriction applies to the following sentences or not. </div></div></div></div></blockquote><div><br></div><div>It doesn't; it's a separate rule. The structure is basically: "If <A>, the result is <B>. If <C>, the result is <D>. The result of anything else is unspecified." It seems weird only because <A> is a subset of <C>.</div><div><br></div><div>John.</div></div></body></html>