Umm... shouldn&#39;t this behavior be commented so that people are not left wondering why it fails and trying to &quot;fix&quot; it?<br><br><div class="gmail_quote">On Wed, Nov 10, 2010 at 16:04, Darin Adler <span dir="ltr">&lt;<a href="mailto:darin@apple.com">darin@apple.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="im">On Nov 10, 2010, at 2:33 PM, Daebarkee Jung wrote:<br>
<br>
&gt; I found that the following lines made errors:<br>
&gt; // OwnPtrCommon.h<br>
&gt; template &lt;typename T&gt; inline void deleteOwnedPtr(T* ptr)<br>
&gt; {<br>
&gt; † † † † typedef char known[sizeof(T) ? 1 : -1];<br>
&gt; † † † † if (sizeof(known))<br>
&gt; † † † † † delete ptr;<br>
&gt; }<br>
&gt;<br>
&gt; I am very curious about why the author wrote like the above.<br>
&gt; What could be the author&#39;s intention?<br>
<br>
</div>The code is to prevent issues like the ones described on these websites:<br>
<br>
<a href="http://stackoverflow.com/questions/1767679/incomplete-type-memory-leaks" target="_blank">http://stackoverflow.com/questions/1767679/incomplete-type-memory-leaks</a><br>
<a href="http://bytes.com/topic/c/answers/611877-gcc-class-forward-declarations-destructor-calls" target="_blank">http://bytes.com/topic/c/answers/611877-gcc-class-forward-declarations-destructor-calls</a><br>
<a href="http://connect.microsoft.com/VisualStudio/feedback/details/231177/delete-of-pointer-to-incomplete-class" target="_blank">http://connect.microsoft.com/VisualStudio/feedback/details/231177/delete-of-pointer-to-incomplete-class</a><br>

<br>
If we delete a pointer and the object has incomplete type, we get undefined behavior. Instead this code causes compilation to fail if the object has incomplete type. The use of a negative number for the size of an array is a way to guarantee we get a compilation error.<br>

<br>
Your alternate version might also work; Iím not sure.<br>
<br>
 † †-- Darin<br>
<br>
_______________________________________________<br>
webkit-dev mailing list<br>
<a href="mailto:webkit-dev@lists.webkit.org">webkit-dev@lists.webkit.org</a><br>
<a href="http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev" target="_blank">http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev</a><br>
</blockquote></div><br>