Skip to content

Commit

Permalink
Fixing compile when uint64_t is 'unsigned long'
Browse files Browse the repository at this point in the history
  • Loading branch information
flamewing committed Oct 10, 2023
1 parent 9db05ac commit 73da98d
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion include/mdcomp/bigendian_io.hh
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ namespace detail {
// supports; but MSVC compiler does not support a 128-bit integer, so this
// is not portable.
template <std::integral T>
[[nodiscard]] CONST_INLINE constexpr T byteswap(T value) noexcept {
[[nodiscard]] CONST_INLINE constexpr T byteswap_impl(T value) noexcept {
#if defined(__cpp_lib_byteswap) && __cpp_lib_byteswap >= 202110L
return std::byteswap(value);
#else
Expand Down Expand Up @@ -241,6 +241,15 @@ namespace detail {
#endif
}

template <std::integral T>
[[nodiscard]] CONST_INLINE constexpr T byteswap(T value) noexcept {
// Need this to handle "(unsigned)? long long" and "(unsigned)? long".
// They can be both 64-bit depending on platform, and which one is used
// in the definition of uint64_t, the other will not match.
return static_cast<T>(
byteswap_impl(static_cast<select_unsigned_t<sizeof(T)>>(value)));
}

template <std::endian endian>
struct endian_base {
private:
Expand Down

0 comments on commit 73da98d

Please sign in to comment.