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.

4583. std::byteswap can make sense for some types with padding bytes

Section: 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.

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.

Proposed resolution:

This wording is relative to N5046.

  1. Modify 22.11.4 [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 (6.9.1 [basic.types.general])For each byte in the object representation of T, bits in the byte are either all padding bits (6.9.1 [basic.types.general]) or all non-padding bits.

    -3- Let the sequence R comprise the bytes of the objectvalue representation of value in reverse order.

    -4- Returns: An object v of type T such that each byte in the objectvalue representation of v is equal to the byte in the corresponding position in R.