Skip to content

Commit 16484e6

Browse files
committed
Fix gdb.error
1 parent f6ac57a commit 16484e6

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
@@ -143,6 +143,7 @@ template <size_t N> struct hash<std::bitset<N>>;
143143
# include <__cstddef/size_t.h>
144144
# include <__functional/hash.h>
145145
# include <__functional/unary_function.h>
146+
# include <__type_traits/integral_constant.h>
146147
# include <__type_traits/is_char_like_type.h>
147148
# include <climits>
148149
# include <stdexcept>
@@ -218,10 +219,10 @@ protected:
218219

219220
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void flip() _NOEXCEPT;
220221
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long to_ulong() const {
221-
return to_ulong(integral_constant < bool, _Size< sizeof(unsigned long) * CHAR_BIT>());
222+
return to_ulong(_BoolConstant < _Size< sizeof(unsigned long) * CHAR_BIT>());
222223
}
223224
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong() const {
224-
return to_ullong(integral_constant < bool, _Size< sizeof(unsigned long long) * CHAR_BIT>());
225+
return to_ullong(_BoolConstant < _Size< sizeof(unsigned long long) * CHAR_BIT>());
225226
}
226227

227228
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool all() const _NOEXCEPT;
@@ -308,7 +309,7 @@ inline _LIBCPP_CONSTEXPR __bitset<_N_words, _Size>::__bitset(unsigned long long
308309
# endif
309310
{
310311
# ifdef _LIBCPP_CXX03_LANG
311-
__init(__v, integral_constant<bool, sizeof(unsigned long long) == sizeof(__storage_type)>());
312+
__init(__v, _BoolConstant<sizeof(unsigned long long) == sizeof(__storage_type)>());
312313
# endif
313314
}
314315

@@ -352,9 +353,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void __bitset<_N_words, _Siz
352353
template <size_t _N_words, size_t _Size>
353354
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long
354355
__bitset<_N_words, _Size>::to_ulong(false_type) const {
355-
__const_iterator __e = __make_iter(_Size);
356-
__const_iterator __i = std::find(__make_iter(sizeof(unsigned long) * CHAR_BIT), __e, true);
357-
if (__i != __e)
356+
if (auto __e = __make_iter(_Size); std::find(__make_iter(sizeof(unsigned long) * CHAR_BIT), __e, true) != __e)
358357
std::__throw_overflow_error("bitset to_ulong overflow error");
359358

360359
return to_ulong(true_type());
@@ -363,7 +362,7 @@ __bitset<_N_words, _Size>::to_ulong(false_type) const {
363362
template <size_t _N_words, size_t _Size>
364363
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long
365364
__bitset<_N_words, _Size>::to_ulong(true_type) const {
366-
return to_ulong(true_type(), integral_constant<bool, sizeof(__storage_type) < sizeof(unsigned long)>());
365+
return to_ulong(true_type(), _BoolConstant<sizeof(__storage_type) < sizeof(unsigned long)>());
367366
}
368367

369368
template <size_t _N_words, size_t _Size>
@@ -378,19 +377,15 @@ __bitset<_N_words, _Size>::to_ulong(true_type, true_type) const {
378377
unsigned long __r = static_cast<unsigned long>(__first_[0]);
379378
_LIBCPP_DIAGNOSTIC_PUSH
380379
_LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wshift-count-overflow")
381-
const size_t __ul_words = sizeof(unsigned long) / sizeof(__storage_type);
382-
const size_t __n_words = _N_words < __ul_words ? _N_words : __ul_words;
383-
for (size_t __i = 1; __i < __n_words; ++__i)
380+
for (size_t __i = 1; __i < _N_words; ++__i)
384381
__r |= static_cast<unsigned long>(__first_[__i]) << (__bits_per_word * __i);
385382
_LIBCPP_DIAGNOSTIC_POP
386383
return __r;
387384
}
388385
template <size_t _N_words, size_t _Size>
389386
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long
390387
__bitset<_N_words, _Size>::to_ullong(false_type) const {
391-
__const_iterator __e = __make_iter(_Size);
392-
__const_iterator __i = std::find(__make_iter(sizeof(unsigned long long) * CHAR_BIT), __e, true);
393-
if (__i != __e)
388+
if (auto __e = __make_iter(_Size); std::find(__make_iter(sizeof(unsigned long long) * CHAR_BIT), __e, true) != __e)
394389
std::__throw_overflow_error("bitset to_ullong overflow error");
395390

396391
return to_ullong(true_type());
@@ -399,7 +394,7 @@ __bitset<_N_words, _Size>::to_ullong(false_type) const {
399394
template <size_t _N_words, size_t _Size>
400395
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long
401396
__bitset<_N_words, _Size>::to_ullong(true_type) const {
402-
return to_ullong(true_type(), integral_constant<bool, sizeof(__storage_type) < sizeof(unsigned long long)>());
397+
return to_ullong(true_type(), _BoolConstant<sizeof(__storage_type) < sizeof(unsigned long long)>());
403398
}
404399

405400
template <size_t _N_words, size_t _Size>
@@ -414,9 +409,7 @@ __bitset<_N_words, _Size>::to_ullong(true_type, true_type) const {
414409
unsigned long long __r = static_cast<unsigned long long>(__first_[0]);
415410
_LIBCPP_DIAGNOSTIC_PUSH
416411
_LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wshift-count-overflow")
417-
const size_t __ull_words = sizeof(unsigned long long) / sizeof(__storage_type);
418-
const size_t __n_words = _N_words < __ull_words ? _N_words : __ull_words;
419-
for (size_t __i = 1; __i < __n_words; ++__i)
412+
for (size_t __i = 1; __i < _N_words; ++__i)
420413
__r |= static_cast<unsigned long long>(__first_[__i]) << (__bits_per_word * __i);
421414
_LIBCPP_DIAGNOSTIC_POP
422415
return __r;
@@ -524,11 +517,7 @@ inline _LIBCPP_CONSTEXPR __bitset<1, _Size>::__bitset() _NOEXCEPT : __first_(0)
524517

525518
template <size_t _Size>
526519
inline _LIBCPP_CONSTEXPR __bitset<1, _Size>::__bitset(unsigned long long __v) _NOEXCEPT
527-
: __first_(static_cast<__storage_type>(__v)) {
528-
// Force __bits_per_word to be instantiated to avoid "gdb.error: There is no member or method named
529-
// __bits_per_word"
530-
(void)__bits_per_word;
531-
}
520+
: __first_(_Size == __bits_per_word ? static_cast<__storage_type>(__v) : static_cast<__storage_type>(__v)) {}
532521

533522
template <size_t _Size>
534523
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void

0 commit comments

Comments
 (0)