This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of New status.
std::byteswap can make sense for some types with padding bytesSection: 22.11.4 [bit.byteswap] Status: New Submitter: Jiang An Opened: 2026-05-21 Last modified: 2026-05-24
Priority: Not Prioritized
View all issues with New status.
Discussion:
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.
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.
Proposed resolution:
This wording is relative to N5046.
Modify 22.11.4 [bit.byteswap] as indicated:
template<class T> constexpr T byteswap(T value) noexcept;-1- Constraints:
-2- Mandates:Tmodelsintegral.For each byte in the object representation ofTdoes not have padding bits (6.9.1 [basic.types.general])T, bits in the byte are either all padding bits (6.9.1 [basic.types.general]) or all non-padding bits. -3- Let the sequenceRcomprise the bytes of theobjectvalue representation of value in reverse order. -4- Returns: An objectvof typeTsuch that each byte in theobjectvalue representation ofvis equal to the byte in the corresponding position inR.