@@ -379,13 +379,13 @@ __bitset<_N_words, _Size>::to_ullong(true_type, false_type) const {
379379template <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}
@@ -626,7 +626,8 @@ public:
626626
627627 // 23.3.5.1 constructors:
628628 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bitset () _NOEXCEPT {}
629- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bitset (unsigned long long __v) _NOEXCEPT : __base(__v) {}
629+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bitset (unsigned long long __v) _NOEXCEPT
630+ : __base(sizeof (unsigned long long ) * CHAR_BIT <= _Size ? __v : __v & ((1ULL << _Size) - 1)) {}
630631 template <class _CharT , __enable_if_t <_IsCharLikeType<_CharT>::value, int > = 0 >
631632 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 explicit bitset (
632633 const _CharT* __str,
0 commit comments