[webkit-dev] deleteOwnedPtr(T* ptr)
darin at apple.com
Wed Nov 10 16:04:04 PST 2010
On Nov 10, 2010, at 2:33 PM, Daebarkee Jung wrote:
> I found that the following lines made errors:
> // OwnPtrCommon.h
> template <typename T> inline void deleteOwnedPtr(T* ptr)
> typedef char known[sizeof(T) ? 1 : -1];
> if (sizeof(known))
> delete ptr;
> I am very curious about why the author wrote like the above.
> What could be the author's intention?
The code is to prevent issues like the ones described on these websites:
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.
Your alternate version might also work; I’m not sure.
More information about the webkit-dev