Skip to content

Commit 159d694

Browse files
[libc++] __uglify internal member names of iterators in bitset (#111127)
[template.bitset.general] indicates that `bitset` shouldn't have member typedef-names `iterator` and `const_iterator`. Currently libc++'s typedef-names are causing ambiguity in name lookup, which isn't conforming. As these iterator types are themselves useful, I think we should just use __uglified member typedef-names for them. Fixes #111125
1 parent 1f919aa commit 159d694

File tree

3 files changed

+72
-22
lines changed

3 files changed

+72
-22
lines changed

libcxx/docs/ReleaseNotes/20.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ Deprecations and Removals
7878
supported as an extension anymore, please migrate any code that uses e.g. ``std::vector<const T>`` to be
7979
standards conforming.
8080

81+
- Non-conforming member typedefs ``iterator`` and ``const_iterator`` of ``std::bitset`` are removed. Previously, they
82+
were private but could cause ambiguity in name lookup. Code that expects such ambiguity will possibly not compile in
83+
LLVM 20.
84+
8185
Upcoming Deprecations and Removals
8286
----------------------------------
8387

libcxx/include/bitset

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@ protected:
187187

188188
typedef __bit_reference<__bitset> reference;
189189
typedef __bit_const_reference<__bitset> const_reference;
190-
typedef __bit_iterator<__bitset, false> iterator;
191-
typedef __bit_iterator<__bitset, true> const_iterator;
190+
typedef __bit_iterator<__bitset, false> __iterator;
191+
typedef __bit_iterator<__bitset, true> __const_iterator;
192192

193193
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT;
194194
_LIBCPP_HIDE_FROM_ABI explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT;
@@ -199,11 +199,11 @@ protected:
199199
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR const_reference __make_ref(size_t __pos) const _NOEXCEPT {
200200
return const_reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);
201201
}
202-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 iterator __make_iter(size_t __pos) _NOEXCEPT {
203-
return iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);
202+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 __iterator __make_iter(size_t __pos) _NOEXCEPT {
203+
return __iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);
204204
}
205-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 const_iterator __make_iter(size_t __pos) const _NOEXCEPT {
206-
return const_iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);
205+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 __const_iterator __make_iter(size_t __pos) const _NOEXCEPT {
206+
return __const_iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);
207207
}
208208

209209
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator&=(const __bitset& __v) _NOEXCEPT;
@@ -335,8 +335,8 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void __bitset<_N_words, _Siz
335335
template <size_t _N_words, size_t _Size>
336336
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long
337337
__bitset<_N_words, _Size>::to_ulong(false_type) const {
338-
const_iterator __e = __make_iter(_Size);
339-
const_iterator __i = std::find(__make_iter(sizeof(unsigned long) * CHAR_BIT), __e, true);
338+
__const_iterator __e = __make_iter(_Size);
339+
__const_iterator __i = std::find(__make_iter(sizeof(unsigned long) * CHAR_BIT), __e, true);
340340
if (__i != __e)
341341
__throw_overflow_error("bitset to_ulong overflow error");
342342

@@ -352,8 +352,8 @@ __bitset<_N_words, _Size>::to_ulong(true_type) const {
352352
template <size_t _N_words, size_t _Size>
353353
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long
354354
__bitset<_N_words, _Size>::to_ullong(false_type) const {
355-
const_iterator __e = __make_iter(_Size);
356-
const_iterator __i = std::find(__make_iter(sizeof(unsigned long long) * CHAR_BIT), __e, true);
355+
__const_iterator __e = __make_iter(_Size);
356+
__const_iterator __i = std::find(__make_iter(sizeof(unsigned long long) * CHAR_BIT), __e, true);
357357
if (__i != __e)
358358
__throw_overflow_error("bitset to_ullong overflow error");
359359

@@ -449,8 +449,8 @@ protected:
449449

450450
typedef __bit_reference<__bitset> reference;
451451
typedef __bit_const_reference<__bitset> const_reference;
452-
typedef __bit_iterator<__bitset, false> iterator;
453-
typedef __bit_iterator<__bitset, true> const_iterator;
452+
typedef __bit_iterator<__bitset, false> __iterator;
453+
typedef __bit_iterator<__bitset, true> __const_iterator;
454454

455455
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT;
456456
_LIBCPP_HIDE_FROM_ABI explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT;
@@ -461,11 +461,11 @@ protected:
461461
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR const_reference __make_ref(size_t __pos) const _NOEXCEPT {
462462
return const_reference(&__first_, __storage_type(1) << __pos);
463463
}
464-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 iterator __make_iter(size_t __pos) _NOEXCEPT {
465-
return iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);
464+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 __iterator __make_iter(size_t __pos) _NOEXCEPT {
465+
return __iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);
466466
}
467-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 const_iterator __make_iter(size_t __pos) const _NOEXCEPT {
468-
return const_iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);
467+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 __const_iterator __make_iter(size_t __pos) const _NOEXCEPT {
468+
return __const_iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);
469469
}
470470

471471
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator&=(const __bitset& __v) _NOEXCEPT;
@@ -564,8 +564,8 @@ protected:
564564

565565
typedef __bit_reference<__bitset> reference;
566566
typedef __bit_const_reference<__bitset> const_reference;
567-
typedef __bit_iterator<__bitset, false> iterator;
568-
typedef __bit_iterator<__bitset, true> const_iterator;
567+
typedef __bit_iterator<__bitset, false> __iterator;
568+
typedef __bit_iterator<__bitset, true> __const_iterator;
569569

570570
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT;
571571
_LIBCPP_HIDE_FROM_ABI explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long) _NOEXCEPT;
@@ -576,11 +576,11 @@ protected:
576576
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR const_reference __make_ref(size_t) const _NOEXCEPT {
577577
return const_reference(nullptr, 1);
578578
}
579-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 iterator __make_iter(size_t) _NOEXCEPT {
580-
return iterator(nullptr, 0);
579+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 __iterator __make_iter(size_t) _NOEXCEPT {
580+
return __iterator(nullptr, 0);
581581
}
582-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 const_iterator __make_iter(size_t) const _NOEXCEPT {
583-
return const_iterator(nullptr, 0);
582+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 __const_iterator __make_iter(size_t) const _NOEXCEPT {
583+
return __const_iterator(nullptr, 0);
584584
}
585585

586586
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator&=(const __bitset&) _NOEXCEPT {}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// <bitset>
10+
11+
// This test ensures that we don't use a non-uglified name 'iterator' and
12+
// 'const_iterator' in the implementation of bitset.
13+
//
14+
// See https://github.com/llvm/llvm-project/issues/111125.
15+
16+
#include <cstddef>
17+
#include <bitset>
18+
#include <type_traits>
19+
20+
struct my_base {
21+
typedef int* iterator;
22+
typedef const int* const_iterator;
23+
};
24+
25+
template <std::size_t N>
26+
struct my_derived : my_base, std::bitset<N> {};
27+
28+
static_assert(std::is_same<my_derived<0>::iterator, int*>::value, "");
29+
static_assert(std::is_same<my_derived<1>::iterator, int*>::value, "");
30+
static_assert(std::is_same<my_derived<8>::iterator, int*>::value, "");
31+
static_assert(std::is_same<my_derived<12>::iterator, int*>::value, "");
32+
static_assert(std::is_same<my_derived<16>::iterator, int*>::value, "");
33+
static_assert(std::is_same<my_derived<32>::iterator, int*>::value, "");
34+
static_assert(std::is_same<my_derived<48>::iterator, int*>::value, "");
35+
static_assert(std::is_same<my_derived<64>::iterator, int*>::value, "");
36+
static_assert(std::is_same<my_derived<96>::iterator, int*>::value, "");
37+
38+
static_assert(std::is_same<my_derived<0>::const_iterator, const int*>::value, "");
39+
static_assert(std::is_same<my_derived<1>::const_iterator, const int*>::value, "");
40+
static_assert(std::is_same<my_derived<8>::const_iterator, const int*>::value, "");
41+
static_assert(std::is_same<my_derived<12>::const_iterator, const int*>::value, "");
42+
static_assert(std::is_same<my_derived<16>::const_iterator, const int*>::value, "");
43+
static_assert(std::is_same<my_derived<32>::const_iterator, const int*>::value, "");
44+
static_assert(std::is_same<my_derived<48>::const_iterator, const int*>::value, "");
45+
static_assert(std::is_same<my_derived<64>::const_iterator, const int*>::value, "");
46+
static_assert(std::is_same<my_derived<96>::const_iterator, const int*>::value, "");

0 commit comments

Comments
 (0)