[libc-commits] [PATCH] D148739: [libc] Use __builtin_bit_cast only when src and dest types are trivially copyable
Siva Chandra via Phabricator via libc-commits
libc-commits at lists.llvm.org
Thu Apr 20 09:11:28 PDT 2023
sivachandra 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)
----------------
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.");
```
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