[libcxx-commits] [PATCH] D75960: [libc++] Implement C++20's P0476r2: std::bit_cast
Mark de Wever via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Aug 25 10:35:11 PDT 2021
Mordante added inline comments.
================
Comment at: libcxx/docs/Status/Cxx20Papers.csv:32
"`P0475R1 <https://wg21.link/P0475R1>`__","LWG","LWG 2511: guaranteed copy elision for piecewise construction","Rapperswil","|Complete|",""
-"`P0476R2 <https://wg21.link/P0476R2>`__","LWG","Bit-casting object representations","Rapperswil","",""
+"`P0476R2 <https://wg21.link/P0476R2>`__","LWG","Bit-casting object representations","Rapperswil","|Complete|","13.0"
"`P0528R3 <https://wg21.link/P0528R3>`__","CWG","The Curious Case of Padding Bits, Featuring Atomic Compare-and-Exchange","Rapperswil","",""
----------------
This should now become 14.
================
Comment at: libcxx/include/__bit/bit_cast.h:28
+ is_trivially_copyable_v<_FromType>
+>>
+_LIBCPP_HIDE_FROM_ABI
----------------
Would it make sense to use concepts instead of `_EnableIf`?
================
Comment at: libcxx/include/__bit/bit_cast.h:31
+constexpr _ToType bit_cast(_FromType const& __from) noexcept {
+ return __builtin_bit_cast(_ToType, __from);
+}
----------------
Quuxplusone wrote:
> Surely this should be guarded by `__has_builtin(__builtin_bit_cast)`. Or is the rationale that we don't need to guard it, because we have no fallback implementation, and so "you get a weird compiler error" is already the best-case outcome on compilers that don't support it? Notice that because `_ToType` is a //type//, not a //value//, you'll get a parse error very eagerly as soon as `<bit>` is included; it's not merely that you'll get an error when you try to //call// `bit_cast`.
>
> It looks like the builtin is supported on Clang 9+ and GCC 11+; it's unsupported on Clang 8- and GCC 10-.
AFAIK all supported platforms, including MSVC now support `__builtin_bit_cast`.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D75960/new/
https://reviews.llvm.org/D75960
More information about the libcxx-commits
mailing list