[libcxx-commits] [PATCH] D75960: [libc++] Implement C++20's P0476r2: std::bit_cast

Zoe Carver via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Wed Jan 13 23:12:36 PST 2021

zoecarver added inline comments.

Comment at: libcxx/test/std/numerics/bit/bit.cast/bit_cast.pass.cpp:208
+// TODO: There doesn't seem to be a way to perform non-trivial correctness
+//       tests inside constexpr.
+constexpr bool basic_constexpr_test() {
zoecarver wrote:
> ldionne wrote:
> > zoecarver wrote:
> > > I assume this means you're against using `__builtin_bit_cast ` to test `std::bit_cast`? Fair enough. 
> > Yes, because `std::bit_cast` is implemented as a single call to `__builtin_bit_cast`. I feel like what we're actually testing here is in fact `__builtin_bit_cast` directly, not just `std::bit_cast`.
> Fair enough. Ideally, Clang's tests would be sufficient, but I see where you're coming from. I think that makes sense. 
> Would it make it better if the call to `__builtin_bit_cast` always casted it to a `char` array and compared the bytes? That would basically be re-implementing memcmp. If we can verify that the cast to `char` array always works, then we can use that to test other things, maybe. 
Here's a Godbolt. I think the issue is just when you try to compare different pointer types with __builtin_memcmp. I guess the earlier approach where you turned off certain asserts in constexpr mode actually makes sense.


  rG LLVM Github Monorepo



More information about the libcxx-commits mailing list