Umm... shouldn't this behavior be commented so that people are not left wondering why it fails and trying to "fix" it?<br><br><div class="gmail_quote">On Wed, Nov 10, 2010 at 16:04, Darin Adler <span dir="ltr"><<a href="mailto:darin@apple.com">darin@apple.com</a>></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>
> I found that the following lines made errors:<br>
> // OwnPtrCommon.h<br>
> template <typename T> inline void deleteOwnedPtr(T* ptr)<br>
> {<br>
> typedef char known[sizeof(T) ? 1 : -1];<br>
> if (sizeof(known))<br>
> delete ptr;<br>
> }<br>
><br>
> I am very curious about why the author wrote like the above.<br>
> What could be the author'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>