Skip to content

Commit 69e4ac8

Browse files
committed
Apply @frederick-vs-ja suggestions to support 16-bit platforms
1 parent c1dfd79 commit 69e4ac8

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

libcxx/include/bitset

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -379,13 +379,13 @@ __bitset<_N_words, _Size>::to_ullong(true_type, false_type) const {
379379
template <size_t _N_words, size_t _Size>
380380
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long
381381
__bitset<_N_words, _Size>::to_ullong(true_type, true_type) const {
382-
unsigned long long __r = __first_[0];
382+
unsigned long long __r = static_cast<unsigned long long>(__first_[0]);
383383
_LIBCPP_DIAGNOSTIC_PUSH
384384
_LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wshift-count-overflow")
385385
const size_t __ull_words = sizeof(unsigned long long) / sizeof(__storage_type);
386-
const size_t __n_words = _N_words < __ull_words ? _N_words : __ull_words;
386+
const size_t __n_words = _N_words < __ull_words ? _N_words : __ull_words;
387387
for (size_t __i = 1; __i < __n_words; ++__i)
388-
__r |= static_cast<unsigned long long>(__first_[__i]) << (sizeof(__storage_type) * CHAR_BIT * __i);
388+
__r |= static_cast<unsigned long long>(__first_[__i]) << (__bits_per_word * __i);
389389
_LIBCPP_DIAGNOSTIC_POP
390390
return __r;
391391
}
@@ -494,8 +494,7 @@ inline _LIBCPP_CONSTEXPR __bitset<1, _Size>::__bitset() _NOEXCEPT : __first_(0)
494494

495495
template <size_t _Size>
496496
inline _LIBCPP_CONSTEXPR __bitset<1, _Size>::__bitset(unsigned long long __v) _NOEXCEPT
497-
: __first_(_Size == __bits_per_word ? static_cast<__storage_type>(__v)
498-
: static_cast<__storage_type>(__v) & ((__storage_type(1) << _Size) - 1)) {}
497+
: __first_(static_cast<__storage_type>(__v)) {}
499498

500499
template <size_t _Size>
501500
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void
@@ -626,7 +625,8 @@ public:
626625

627626
// 23.3.5.1 constructors:
628627
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bitset() _NOEXCEPT {}
629-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bitset(unsigned long long __v) _NOEXCEPT : __base(__v) {}
628+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bitset(unsigned long long __v) _NOEXCEPT
629+
: __base(sizeof(unsigned long long) * CHAR_BIT <= _Size ? __v : __v & ((1ULL << _Size) - 1)) {}
630630
template <class _CharT, __enable_if_t<_IsCharLikeType<_CharT>::value, int> = 0>
631631
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 explicit bitset(
632632
const _CharT* __str,

0 commit comments

Comments
 (0)