Skip to content

Commit d462d7b

Browse files
committed
Fix gdb.error
1 parent 54df6ee commit d462d7b

File tree

1 file changed

+11
-22
lines changed

1 file changed

+11
-22
lines changed

libcxx/include/bitset

+11-22
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ template <size_t N> struct hash<std::bitset<N>>;
144144
# include <__cstddef/size_t.h>
145145
# include <__functional/hash.h>
146146
# include <__functional/unary_function.h>
147+
# include <__type_traits/integral_constant.h>
147148
# include <__type_traits/is_char_like_type.h>
148149
# include <climits>
149150
# include <stdexcept>
@@ -219,10 +220,10 @@ protected:
219220

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

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

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

359358
return to_ulong(true_type());
@@ -362,7 +361,7 @@ __bitset<_N_words, _Size>::to_ulong(false_type) const {
362361
template <size_t _N_words, size_t _Size>
363362
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long
364363
__bitset<_N_words, _Size>::to_ulong(true_type) const {
365-
return to_ulong(true_type(), integral_constant<bool, sizeof(__storage_type) < sizeof(unsigned long)>());
364+
return to_ulong(true_type(), _BoolConstant<sizeof(__storage_type) < sizeof(unsigned long)>());
366365
}
367366

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

395390
return to_ullong(true_type());
@@ -398,7 +393,7 @@ __bitset<_N_words, _Size>::to_ullong(false_type) const {
398393
template <size_t _N_words, size_t _Size>
399394
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long
400395
__bitset<_N_words, _Size>::to_ullong(true_type) const {
401-
return to_ullong(true_type(), integral_constant<bool, sizeof(__storage_type) < sizeof(unsigned long long)>());
396+
return to_ullong(true_type(), _BoolConstant<sizeof(__storage_type) < sizeof(unsigned long long)>());
402397
}
403398

404399
template <size_t _N_words, size_t _Size>
@@ -413,9 +408,7 @@ __bitset<_N_words, _Size>::to_ullong(true_type, true_type) const {
413408
unsigned long long __r = static_cast<unsigned long long>(__first_[0]);
414409
_LIBCPP_DIAGNOSTIC_PUSH
415410
_LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wshift-count-overflow")
416-
const size_t __ull_words = sizeof(unsigned long long) / sizeof(__storage_type);
417-
const size_t __n_words = _N_words < __ull_words ? _N_words : __ull_words;
418-
for (size_t __i = 1; __i < __n_words; ++__i)
411+
for (size_t __i = 1; __i < _N_words; ++__i)
419412
__r |= static_cast<unsigned long long>(__first_[__i]) << (__bits_per_word * __i);
420413
_LIBCPP_DIAGNOSTIC_POP
421414
return __r;
@@ -523,11 +516,7 @@ inline _LIBCPP_CONSTEXPR __bitset<1, _Size>::__bitset() _NOEXCEPT : __first_(0)
523516

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

532521
template <size_t _Size>
533522
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void

0 commit comments

Comments
 (0)