Skip to content

Commit b0ea215

Browse files
committed
Fix ambiguity due to non-uglified member typedefs
1 parent 1c99907 commit b0ea215

File tree

7 files changed

+79
-31
lines changed

7 files changed

+79
-31
lines changed

libcxx/include/__algorithm/count.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ __count(_Iter __first, _Sent __last, const _Tp& __value, _Proj& __proj) {
4444
// __bit_iterator implementation
4545
template <bool _ToCount, class _Cp, bool _IsConst>
4646
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 typename __bit_iterator<_Cp, _IsConst>::difference_type
47-
__count_bool(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __n) {
47+
__count_bool(__bit_iterator<_Cp, _IsConst> __first, typename __size_difference_type_traits<_Cp>::size_type __n) {
4848
using _It = __bit_iterator<_Cp, _IsConst>;
4949
using __storage_type = typename _It::__storage_type;
5050
using difference_type = typename _It::difference_type;
@@ -75,8 +75,10 @@ template <class, class _Cp, bool _IsConst, class _Tp, class _Proj, __enable_if_t
7575
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __iter_diff_t<__bit_iterator<_Cp, _IsConst> >
7676
__count(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, const _Tp& __value, _Proj&) {
7777
if (__value)
78-
return std::__count_bool<true>(__first, static_cast<typename _Cp::size_type>(__last - __first));
79-
return std::__count_bool<false>(__first, static_cast<typename _Cp::size_type>(__last - __first));
78+
return std::__count_bool<true>(
79+
__first, static_cast<typename __size_difference_type_traits<_Cp>::size_type>(__last - __first));
80+
return std::__count_bool<false>(
81+
__first, static_cast<typename __size_difference_type_traits<_Cp>::size_type>(__last - __first));
8082
}
8183

8284
template <class _InputIterator, class _Tp>

libcxx/include/__algorithm/fill_n.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ __fill_n(_OutputIterator __first, _Size __n, const _Tp& __value);
3232

3333
template <bool _FillVal, class _Cp>
3434
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
35-
__fill_n_bool(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __n) {
35+
__fill_n_bool(__bit_iterator<_Cp, false> __first, typename __size_difference_type_traits<_Cp>::size_type __n) {
3636
using _It = __bit_iterator<_Cp, false>;
3737
using __storage_type = typename _It::__storage_type;
3838

libcxx/include/__algorithm/find.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ __find(_Tp* __first, _Tp* __last, const _Up& __value, _Proj& __proj) {
9797
// __bit_iterator implementation
9898
template <bool _ToFind, class _Cp, bool _IsConst>
9999
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI __bit_iterator<_Cp, _IsConst>
100-
__find_bool(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __n) {
100+
__find_bool(__bit_iterator<_Cp, _IsConst> __first, typename __size_difference_type_traits<_Cp>::size_type __n) {
101101
using _It = __bit_iterator<_Cp, _IsConst>;
102102
using __storage_type = typename _It::__storage_type;
103103

@@ -135,8 +135,10 @@ template <class _Cp, bool _IsConst, class _Tp, class _Proj, __enable_if_t<__is_i
135135
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_iterator<_Cp, _IsConst>
136136
__find(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, const _Tp& __value, _Proj&) {
137137
if (static_cast<bool>(__value))
138-
return std::__find_bool<true>(__first, static_cast<typename _Cp::size_type>(__last - __first));
139-
return std::__find_bool<false>(__first, static_cast<typename _Cp::size_type>(__last - __first));
138+
return std::__find_bool<true>(
139+
__first, static_cast<typename __size_difference_type_traits<_Cp>::size_type>(__last - __first));
140+
return std::__find_bool<false>(
141+
__first, static_cast<typename __size_difference_type_traits<_Cp>::size_type>(__last - __first));
140142
}
141143

142144
// segmented iterator implementation

libcxx/include/__bit_reference

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <__bit/countr.h>
1616
#include <__compare/ordering.h>
1717
#include <__config>
18+
#include <__cstddef/ptrdiff_t.h>
1819
#include <__cstddef/size_t.h>
1920
#include <__fwd/bit_reference.h>
2021
#include <__iterator/iterator_traits.h>
@@ -41,6 +42,12 @@ struct __has_storage_type {
4142
static const bool value = false;
4243
};
4344

45+
template <typename _Cp>
46+
struct __size_difference_type_traits {
47+
using difference_type = typename _Cp::difference_type;
48+
using size_type = typename _Cp::size_type;
49+
};
50+
4451
template <class _Cp, bool = __has_storage_type<_Cp>::value>
4552
class __bit_reference {
4653
using __storage_type _LIBCPP_NODEBUG = typename _Cp::__storage_type;
@@ -587,10 +594,10 @@ inline _LIBCPP_HIDE_FROM_ABI __bit_iterator<_Cr, false> swap_ranges(
587594

588595
template <class _Cp>
589596
struct __bit_array {
590-
using difference_type _LIBCPP_NODEBUG = typename _Cp::difference_type;
591-
using __storage_type _LIBCPP_NODEBUG = typename _Cp::__storage_type;
597+
using difference_type _LIBCPP_NODEBUG = typename __size_difference_type_traits<_Cp>::difference_type;
598+
using __storage_type _LIBCPP_NODEBUG = typename _Cp::__storage_type;
592599
using __storage_pointer _LIBCPP_NODEBUG = typename _Cp::__storage_pointer;
593-
using iterator _LIBCPP_NODEBUG = typename _Cp::iterator;
600+
using iterator _LIBCPP_NODEBUG = typename _Cp::iterator;
594601

595602
static const unsigned __bits_per_word = _Cp::__bits_per_word;
596603
static const unsigned _Np = 4;
@@ -779,7 +786,7 @@ equal(__bit_iterator<_Cp, _IC1> __first1, __bit_iterator<_Cp, _IC1> __last1, __b
779786
template <class _Cp, bool _IsConst, typename _Cp::__storage_type>
780787
class __bit_iterator {
781788
public:
782-
using difference_type = typename _Cp::difference_type;
789+
using difference_type = typename __size_difference_type_traits<_Cp>::difference_type;
783790
using value_type = bool;
784791
using pointer = __bit_iterator;
785792
#ifndef _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL
@@ -966,7 +973,7 @@ private:
966973

967974
template <bool _FillVal, class _Dp>
968975
_LIBCPP_CONSTEXPR_SINCE_CXX20 friend void
969-
__fill_n_bool(__bit_iterator<_Dp, false> __first, typename _Dp::size_type __n);
976+
__fill_n_bool(__bit_iterator<_Dp, false> __first, typename __size_difference_type_traits<_Dp>::size_type __n);
970977

971978
template <class _Dp, bool _IC>
972979
_LIBCPP_CONSTEXPR_SINCE_CXX20 friend __bit_iterator<_Dp, false> __copy_aligned(
@@ -1009,10 +1016,10 @@ private:
10091016
equal(__bit_iterator<_Dp, _IC1>, __bit_iterator<_Dp, _IC1>, __bit_iterator<_Dp, _IC2>);
10101017
template <bool _ToFind, class _Dp, bool _IC>
10111018
_LIBCPP_CONSTEXPR_SINCE_CXX20 friend __bit_iterator<_Dp, _IC>
1012-
__find_bool(__bit_iterator<_Dp, _IC>, typename _Dp::size_type);
1019+
__find_bool(__bit_iterator<_Dp, _IC>, typename __size_difference_type_traits<_Dp>::size_type);
10131020
template <bool _ToCount, class _Dp, bool _IC>
1014-
friend typename __bit_iterator<_Dp, _IC>::difference_type _LIBCPP_HIDE_FROM_ABI
1015-
_LIBCPP_CONSTEXPR_SINCE_CXX20 __count_bool(__bit_iterator<_Dp, _IC>, typename _Dp::size_type);
1021+
friend typename __bit_iterator<_Dp, _IC>::difference_type _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
1022+
__count_bool(__bit_iterator<_Dp, _IC>, typename __size_difference_type_traits<_Dp>::size_type);
10161023
};
10171024

10181025
_LIBCPP_END_NAMESPACE_STD

libcxx/include/__fwd/bit_reference.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2020
template <class _Cp, bool _IsConst, typename _Cp::__storage_type = 0>
2121
class __bit_iterator;
2222

23+
template <typename _Cp>
24+
struct __size_difference_type_traits;
25+
2326
_LIBCPP_END_NAMESPACE_STD
2427

2528
#endif // _LIBCPP___FWD_BIT_REFERENCE_H

libcxx/include/bitset

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ template <size_t N> struct hash<std::bitset<N>>;
136136
# include <__assert>
137137
# include <__bit_reference>
138138
# include <__config>
139+
# include <__cstddef/ptrdiff_t.h>
140+
# include <__cstddef/size_t.h>
139141
# include <__functional/hash.h>
140142
# include <__functional/unary_function.h>
141143
# include <__type_traits/is_char_like_type.h>
@@ -167,12 +169,18 @@ struct __has_storage_type<__bitset<_N_words, _Size> > {
167169
static const bool value = true;
168170
};
169171

172+
template <size_t _N_words, size_t _Size>
173+
struct __size_difference_type_traits<std::__bitset<_N_words, _Size> > {
174+
using difference_type = typename std::__bitset<_N_words, _Size>::__difference_type;
175+
using size_type = typename std::__bitset<_N_words, _Size>::__size_type;
176+
};
177+
170178
template <size_t _N_words, size_t _Size>
171179
class __bitset {
172180
public:
173-
typedef ptrdiff_t difference_type;
174-
typedef size_t size_type;
175-
typedef size_type __storage_type;
181+
typedef ptrdiff_t __difference_type;
182+
typedef size_t __size_type;
183+
typedef size_t __storage_type;
176184

177185
protected:
178186
typedef __bitset __self;
@@ -301,28 +309,28 @@ inline _LIBCPP_CONSTEXPR __bitset<_N_words, _Size>::__bitset(unsigned long long
301309
template <size_t _N_words, size_t _Size>
302310
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void
303311
__bitset<_N_words, _Size>::operator&=(const __bitset& __v) _NOEXCEPT {
304-
for (size_type __i = 0; __i < _N_words; ++__i)
312+
for (size_t __i = 0; __i < _N_words; ++__i)
305313
__first_[__i] &= __v.__first_[__i];
306314
}
307315

308316
template <size_t _N_words, size_t _Size>
309317
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void
310318
__bitset<_N_words, _Size>::operator|=(const __bitset& __v) _NOEXCEPT {
311-
for (size_type __i = 0; __i < _N_words; ++__i)
319+
for (size_t __i = 0; __i < _N_words; ++__i)
312320
__first_[__i] |= __v.__first_[__i];
313321
}
314322

315323
template <size_t _N_words, size_t _Size>
316324
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void
317325
__bitset<_N_words, _Size>::operator^=(const __bitset& __v) _NOEXCEPT {
318-
for (size_type __i = 0; __i < _N_words; ++__i)
326+
for (size_t __i = 0; __i < _N_words; ++__i)
319327
__first_[__i] ^= __v.__first_[__i];
320328
}
321329

322330
template <size_t _N_words, size_t _Size>
323331
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void __bitset<_N_words, _Size>::flip() _NOEXCEPT {
324332
// do middle whole words
325-
size_type __n = _Size;
333+
size_t __n = _Size;
326334
__storage_pointer __p = __first_;
327335
for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
328336
*__p = ~*__p;
@@ -390,7 +398,7 @@ __bitset<_N_words, _Size>::to_ullong(true_type, true_type) const {
390398
template <size_t _N_words, size_t _Size>
391399
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool __bitset<_N_words, _Size>::all() const _NOEXCEPT {
392400
// do middle whole words
393-
size_type __n = _Size;
401+
size_t __n = _Size;
394402
__const_storage_pointer __p = __first_;
395403
for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
396404
if (~*__p)
@@ -407,7 +415,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool __bitset<_N_words, _Siz
407415
template <size_t _N_words, size_t _Size>
408416
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool __bitset<_N_words, _Size>::any() const _NOEXCEPT {
409417
// do middle whole words
410-
size_type __n = _Size;
418+
size_t __n = _Size;
411419
__const_storage_pointer __p = __first_;
412420
for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
413421
if (*__p)
@@ -424,17 +432,17 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool __bitset<_N_words, _Siz
424432
template <size_t _N_words, size_t _Size>
425433
inline size_t __bitset<_N_words, _Size>::__hash_code() const _NOEXCEPT {
426434
size_t __h = 0;
427-
for (size_type __i = 0; __i < _N_words; ++__i)
435+
for (size_t __i = 0; __i < _N_words; ++__i)
428436
__h ^= __first_[__i];
429437
return __h;
430438
}
431439

432440
template <size_t _Size>
433441
class __bitset<1, _Size> {
434442
public:
435-
typedef ptrdiff_t difference_type;
436-
typedef size_t size_type;
437-
typedef size_type __storage_type;
443+
typedef ptrdiff_t __difference_type;
444+
typedef size_t __size_type;
445+
typedef size_t __storage_type;
438446

439447
protected:
440448
typedef __bitset __self;
@@ -549,9 +557,9 @@ inline size_t __bitset<1, _Size>::__hash_code() const _NOEXCEPT {
549557
template <>
550558
class __bitset<0, 0> {
551559
public:
552-
typedef ptrdiff_t difference_type;
553-
typedef size_t size_type;
554-
typedef size_type __storage_type;
560+
typedef ptrdiff_t __difference_type;
561+
typedef size_t __size_type;
562+
typedef size_t __storage_type;
555563

556564
protected:
557565
typedef __bitset __self;

libcxx/test/std/utilities/template.bitset/bitset.members/nonstdmem.uglified.compile.pass.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ struct my_base {
2424
typedef int* iterator;
2525
typedef const int* const_iterator;
2626
typedef my_base base;
27+
<<<<<<< HEAD
2728
typedef const int& const_reference;
29+
=======
30+
typedef std::ptrdiff_t difference_type;
31+
typedef std::size_t size_type;
32+
>>>>>>> 620da4a790b5 (Fix ambiguity due to non-uglified member typedefs)
2833
};
2934

3035
template <std::size_t N>
@@ -69,3 +74,24 @@ static_assert(std::is_same<my_derived<32>::const_reference, const int&>::value,
6974
static_assert(std::is_same<my_derived<48>::const_reference, const int&>::value, "");
7075
static_assert(std::is_same<my_derived<64>::const_reference, const int&>::value, "");
7176
static_assert(std::is_same<my_derived<96>::const_reference, const int&>::value, "");
77+
78+
static_assert(std::is_same<my_derived<0>::difference_type, std::ptrdiff_t>::value, "");
79+
static_assert(std::is_same<my_derived<1>::difference_type, std::ptrdiff_t>::value, "");
80+
static_assert(std::is_same<my_derived<8>::difference_type, std::ptrdiff_t>::value, "");
81+
static_assert(std::is_same<my_derived<12>::difference_type, std::ptrdiff_t>::value, "");
82+
static_assert(std::is_same<my_derived<16>::difference_type, std::ptrdiff_t>::value, "");
83+
static_assert(std::is_same<my_derived<32>::difference_type, std::ptrdiff_t>::value, "");
84+
static_assert(std::is_same<my_derived<48>::difference_type, std::ptrdiff_t>::value, "");
85+
static_assert(std::is_same<my_derived<64>::difference_type, std::ptrdiff_t>::value, "");
86+
static_assert(std::is_same<my_derived<96>::difference_type, std::ptrdiff_t>::value, "");
87+
88+
static_assert(std::is_same<my_derived<0>::size_type, std::size_t>::value, "");
89+
static_assert(std::is_same<my_derived<1>::size_type, std::size_t>::value, "");
90+
static_assert(std::is_same<my_derived<8>::size_type, std::size_t>::value, "");
91+
static_assert(std::is_same<my_derived<12>::size_type, std::size_t>::value, "");
92+
static_assert(std::is_same<my_derived<16>::size_type, std::size_t>::value, "");
93+
static_assert(std::is_same<my_derived<32>::size_type, std::size_t>::value, "");
94+
static_assert(std::is_same<my_derived<48>::size_type, std::size_t>::value, "");
95+
static_assert(std::is_same<my_derived<64>::size_type, std::size_t>::value, "");
96+
static_assert(std::is_same<my_derived<96>::size_type, std::size_t>::value, "");
97+
>>>>>>> 620da4a790b5 (Fix ambiguity due to non-uglified member typedefs)

0 commit comments

Comments
 (0)