Skip to content

Commit 8966964

Browse files
committed
Fix gdb.error
1 parent e1fb50d commit 8966964

File tree

1 file changed

+11
-22
lines changed

1 file changed

+11
-22
lines changed

libcxx/include/bitset

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ template <size_t N> struct hash<std::bitset<N>>;
147147
# include <__functional/hash.h>
148148
# include <__functional/identity.h>
149149
# include <__functional/unary_function.h>
150+
# include <__type_traits/integral_constant.h>
150151
# include <__type_traits/is_char_like_type.h>
151152
# include <climits>
152153
# include <stdexcept>
@@ -222,10 +223,10 @@ protected:
222223

223224
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void flip() _NOEXCEPT;
224225
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long to_ulong() const {
225-
return to_ulong(integral_constant < bool, _Size< sizeof(unsigned long) * CHAR_BIT>());
226+
return to_ulong(_BoolConstant < _Size< sizeof(unsigned long) * CHAR_BIT>());
226227
}
227228
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong() const {
228-
return to_ullong(integral_constant < bool, _Size< sizeof(unsigned long long) * CHAR_BIT>());
229+
return to_ullong(_BoolConstant < _Size< sizeof(unsigned long long) * CHAR_BIT>());
229230
}
230231

231232
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool all() const _NOEXCEPT { return !__scan_bits(__bit_not()); }
@@ -342,7 +343,7 @@ inline _LIBCPP_CONSTEXPR __bitset<_N_words, _Size>::__bitset(unsigned long long
342343
# endif
343344
{
344345
# ifdef _LIBCPP_CXX03_LANG
345-
__init(__v, integral_constant<bool, sizeof(unsigned long long) <= sizeof(__storage_type)>());
346+
__init(__v, _BoolConstant<sizeof(unsigned long long) <= sizeof(__storage_type)>());
346347
# endif
347348
}
348349

@@ -384,9 +385,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void __bitset<_N_words, _Siz
384385
template <size_t _N_words, size_t _Size>
385386
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long
386387
__bitset<_N_words, _Size>::to_ulong(false_type) const {
387-
__const_iterator __e = __make_iter(_Size);
388-
__const_iterator __i = std::find(__make_iter(sizeof(unsigned long) * CHAR_BIT), __e, true);
389-
if (__i != __e)
388+
if (auto __e = __make_iter(_Size); std::find(__make_iter(sizeof(unsigned long) * CHAR_BIT), __e, true) != __e)
390389
std::__throw_overflow_error("bitset to_ulong overflow error");
391390

392391
return to_ulong(true_type());
@@ -395,7 +394,7 @@ __bitset<_N_words, _Size>::to_ulong(false_type) const {
395394
template <size_t _N_words, size_t _Size>
396395
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long
397396
__bitset<_N_words, _Size>::to_ulong(true_type) const {
398-
return to_ulong(true_type(), integral_constant<bool, sizeof(__storage_type) < sizeof(unsigned long)>());
397+
return to_ulong(true_type(), _BoolConstant<sizeof(__storage_type) < sizeof(unsigned long)>());
399398
}
400399

401400
template <size_t _N_words, size_t _Size>
@@ -410,19 +409,15 @@ __bitset<_N_words, _Size>::to_ulong(true_type, true_type) const {
410409
unsigned long __r = static_cast<unsigned long>(__first_[0]);
411410
_LIBCPP_DIAGNOSTIC_PUSH
412411
_LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wshift-count-overflow")
413-
const size_t __ul_words = sizeof(unsigned long) / sizeof(__storage_type);
414-
const size_t __n_words = _N_words < __ul_words ? _N_words : __ul_words;
415-
for (size_t __i = 1; __i < __n_words; ++__i)
412+
for (size_t __i = 1; __i < _N_words; ++__i)
416413
__r |= static_cast<unsigned long>(__first_[__i]) << (__bits_per_word * __i);
417414
_LIBCPP_DIAGNOSTIC_POP
418415
return __r;
419416
}
420417
template <size_t _N_words, size_t _Size>
421418
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long
422419
__bitset<_N_words, _Size>::to_ullong(false_type) const {
423-
__const_iterator __e = __make_iter(_Size);
424-
__const_iterator __i = std::find(__make_iter(sizeof(unsigned long long) * CHAR_BIT), __e, true);
425-
if (__i != __e)
420+
if (auto __e = __make_iter(_Size); std::find(__make_iter(sizeof(unsigned long long) * CHAR_BIT), __e, true) != __e)
426421
std::__throw_overflow_error("bitset to_ullong overflow error");
427422

428423
return to_ullong(true_type());
@@ -431,7 +426,7 @@ __bitset<_N_words, _Size>::to_ullong(false_type) const {
431426
template <size_t _N_words, size_t _Size>
432427
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long
433428
__bitset<_N_words, _Size>::to_ullong(true_type) const {
434-
return to_ullong(true_type(), integral_constant<bool, sizeof(__storage_type) < sizeof(unsigned long long)>());
429+
return to_ullong(true_type(), _BoolConstant<sizeof(__storage_type) < sizeof(unsigned long long)>());
435430
}
436431

437432
template <size_t _N_words, size_t _Size>
@@ -446,9 +441,7 @@ __bitset<_N_words, _Size>::to_ullong(true_type, true_type) const {
446441
unsigned long long __r = static_cast<unsigned long long>(__first_[0]);
447442
_LIBCPP_DIAGNOSTIC_PUSH
448443
_LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wshift-count-overflow")
449-
const size_t __ull_words = sizeof(unsigned long long) / sizeof(__storage_type);
450-
const size_t __n_words = _N_words < __ull_words ? _N_words : __ull_words;
451-
for (size_t __i = 1; __i < __n_words; ++__i)
444+
for (size_t __i = 1; __i < _N_words; ++__i)
452445
__r |= static_cast<unsigned long long>(__first_[__i]) << (__bits_per_word * __i);
453446
_LIBCPP_DIAGNOSTIC_POP
454447
return __r;
@@ -540,11 +533,7 @@ inline _LIBCPP_CONSTEXPR __bitset<1, _Size>::__bitset() _NOEXCEPT : __first_(0)
540533

541534
template <size_t _Size>
542535
inline _LIBCPP_CONSTEXPR __bitset<1, _Size>::__bitset(unsigned long long __v) _NOEXCEPT
543-
: __first_(static_cast<__storage_type>(__v)) {
544-
// Force __bits_per_word to be instantiated to avoid "gdb.error: There is no member or method named
545-
// __bits_per_word"
546-
(void)__bits_per_word;
547-
}
536+
: __first_(_Size == __bits_per_word ? static_cast<__storage_type>(__v) : static_cast<__storage_type>(__v)) {}
548537

549538
template <size_t _Size>
550539
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void

0 commit comments

Comments
 (0)