[libcxx-commits] [libcxx] [libc++] std::byteswap support for _BitInt(N) (PR #196512)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Fri May 29 01:57:54 PDT 2026
================
@@ -24,26 +28,41 @@ _LIBCPP_BEGIN_NAMESPACE_STD
template <integral _Tp>
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp byteswap(_Tp __val) noexcept {
+ // [bit.byteswap]/Mandates: T does not have padding bits.
+ // bool is grandfathered: every shipping implementation admits it and the
+ // size-1 identity path can't shuffle padding bits into value positions.
+ // LWG 4583 proposes relaxing this to allow byte-aligned padding (e.g.
+ // _BitInt(48) where 2 whole bytes are padding); revisit once it resolves.
+ static_assert(is_same_v<remove_cv_t<_Tp>, bool> ||
+ numeric_limits<_Tp>::digits + numeric_limits<_Tp>::is_signed == sizeof(_Tp) * CHAR_BIT,
+ "std::byteswap requires T to have no padding bits");
+
if constexpr (sizeof(_Tp) == 1) {
return __val;
----------------
philnik777 wrote:
How is this related to `__int128`?
https://github.com/llvm/llvm-project/pull/196512
More information about the libcxx-commits
mailing list