[libc-commits] [PATCH] D148739: [libc] Use __builtin_bit_cast only when src and dest types are trivially copyable
Mikhail Ramalho via Phabricator via libc-commits
libc-commits at lists.llvm.org
Thu Apr 20 09:26:46 PDT 2023
mikhail.ramalho added inline comments.
================
Comment at: libc/src/__support/CPP/bit.h:32
+ cpp::is_trivially_copyable<From>::value)
+ return __builtin_bit_cast(To, from);
+#endif // defined(LLVM_LIBC_HAS_BUILTIN_BIT_CAST)
----------------
sivachandra wrote:
> I am on the fence about this. Should we be bit-casting instances of classes which are not trivially copyable? So, may be add something like this instead of trying to bit-cast:
>
> ```
> static_assert(cpp::is_trivially_copyable<To>::value && cpp::is_trivially_copyable<From>::value,
> "Cannot bit-cast instances of non-trivially copyable classes.");
> ```
alright
BTW, in the possible implementation section of https://en.cppreference.com/w/cpp/numeric/bit_cast it also requires the dest type to be trivially constructible when using memcpy, should I add it too?
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D148739/new/
https://reviews.llvm.org/D148739
More information about the libc-commits
mailing list