Bug 16317 - Add strict_aliasing_cast<T>() to avoid need for custom unions
Summary: Add strict_aliasing_cast<T>() to avoid need for custom unions
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: 523.x (Safari 3)
Hardware: Mac OS X 10.4
: P2 Normal
Assignee: Nobody
URL: http://trac.webkit.org/projects/webki...
Keywords:
Depends on:
Blocks:
 
Reported: 2007-12-05 19:08 PST by Eric Seidel (no email)
Modified: 2009-10-23 15:44 PDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Eric Seidel (no email) 2007-12-05 19:08:19 PST
Add strict_aliasing_cast<T>() to avoid need for custom unions

We could do things like:
http://trac.webkit.org/projects/webkit/changeset/28455

Using a template function, which I think might lead to more readable code:

template<type T, type S>
strict_aliasing_cast<T>(S original)
{
    union TmpUnion {
        S original;
        T casted;
    };

    TmpUnion u;
    u.original = original;
    return u.casted;
}

then that change just becomes:

return strict_aliasing_cast<TMalloc_Heap*>(&pageheap_memory[0]);
Comment 1 Eric Seidel (no email) 2008-02-25 23:27:54 PST
Didn't sam already add something like this?  If so, this should be closed.
Comment 2 Martin Robinson 2009-10-23 15:44:28 PDT
If I'm not mistaken, this looks to be bitwise_cast in JavaScriptCore/wtf/StdLibExtras.h. So this bug can probably be closed.