This is an archive of the discontinued LLVM Phabricator instance.

[ADT] bit_cast: check for is_trivially_copyable more portably
ClosedPublic

Authored by jfb on Sep 10 2018, 1:37 PM.

Details

Summary

It turns out that isPodLike isn't a good workaround for is_trivially_copyable for bit_cast's purpose. In D51872 Louis points out that tuple and pair really aren't a good fit, and for bit_cast I want to capture array. This patch instead checks is_trivially_copyable directly in bit_cast for all but GCC 4.x. In GCC 4.x developers only check for sizeof match, which means any mistake they make will succeed locally and fail on the bots. Realistically that's few developers and they'll be left behind once we upgrade past C++11.

This will allow using bit_cast with std::array.

Diff Detail

Repository
rL LLVM

Event Timeline

jfb created this revision.Sep 10 2018, 1:37 PM

I think that works because memcpy this way is valid IFF To and From are trivially copyable. LGTM.

This revision was not accepted when it landed; it landed in state Needs Review.Sep 10 2018, 2:35 PM
This revision was automatically updated to reflect the committed changes.
jfb added a comment.Sep 10 2018, 2:42 PM

Extra fix in r341866 because __is_trivially_copyable is a function-like builtin, not a template.

jfb added a comment.Sep 10 2018, 2:44 PM

And r341867 because I committed before saving the file edit...