Created on 2026-05-21.00:00:00 last changed 1 week ago
Proposed resolution:
This wording is relative to N5046.
Modify [bit.byteswap] as indicated:
template<class T> constexpr T byteswap(T value) noexcept;-1- Constraints: `T` models `integral`.
-2- Mandates:`T` does not have padding bits ([basic.types.general])For each byte in the object representation of `T`, bits in the byte are either all padding bits ([basic.types.general]) or all non-padding bits. -3- Let the sequence R comprise the bytes of theobjectvalue representation of value in reverse order. -4- Returns: An object `v` of type `T` such that each byte in theobjectvalue representation of `v` is equal to the byte in the corresponding position in R.
Currently, `std::byteswap` doesn't accept types with padding bits. The prohibition might be a bit too strict. E.g., if the implementation provides `__int48` such that `sizeof(__int48) == 8` and there're 2 padding bytes in the object representation of `__int48`, `std::byteswap` can arguably make sense for `__int48` if we specify its semantics as reversing byte order of the value representation instead of the object representation. Some implementors (see llvm/llvm-project#196512) think that it's meaningful make `std::byteswap` support `__int48` and its friends.
The issue was discovered when making `std::byteswap` support `_BitInt` in libc++. While `_BitInt` is being standardized in C++ via P3666R4, libc++ is trying to recognize (`unsigned`) `_BitInt(N)` as extended integer types and achieve full library support.| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2026-05-24 09:51:11 | admin | set | messages: + msg16324 |
| 2026-05-21 00:00:00 | admin | create | |