[cfe-commits] RFC - Fix std::hash bugs and remove reinterpret_cast<>

Chandler Carruth chandlerc at google.com
Fri Dec 2 14:40:09 PST 2011


On Fri, Dec 2, 2011 at 1:00 PM, Dave Zarzycki <zarzycki at apple.com> wrote:

> +        if (sizeof(double) == sizeof(size_t)) {
> +            union {
> +                double __f;
> +                size_t __d;
> +            } __u;
> +            __u.__f = __v;
> +            return __u.__d;
>

This still isn't well defined. The way to do this correctly according to
the standard is to use 'memcpy' to copy the bytes into your size_t variable
and return that. This shouldn't ever result in an actual call to memcpy. If
it does on any platform due to insufficient optimizers, we could easily add
a call to __builtin_memcpy() (or the equivalent) on those platforms.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20111202/94b8a61b/attachment.html>


More information about the cfe-commits mailing list