Skip to content

Commit b7ad08c

Browse files
[libc++] Avoid overloaded operator, for (T, Iter) cases
Several components in libc++ aren't defending against overloaded `operator,(T, Iter)` currently. Existing deleted overloads in `test_iterators.h` are insufficient for such cases. This PR adds corresponding deleted overloads with reversed order and fixes these libc++ components. - `piecewise_linear_distribution`'s iterator pair constructor, - `piecewise_linear_distribution::param_type`'s iterator pair constructor, - `piecewise_constant_distribution`'s iterator pair constructor, - `piecewise_constant_distribution::param_type`'s iterator pair constructor, - `money_get::do_get`, - `money_put::do_put`, and - `num_put::do_put`.
1 parent 1ab4113 commit b7ad08c

36 files changed

+118
-31
lines changed

libcxx/include/__locale_dir/money.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ bool money_get<_CharT, _InputIterator>::__do_get(
433433
__err |= ios_base::failbit;
434434
return false;
435435
}
436-
for (++__b; __fd > 0; --__fd, ++__b) {
436+
for (++__b; __fd > 0; --__fd, (void)++__b) {
437437
if (__b == __e || !__ct.is(ctype_base::digit, *__b)) {
438438
__err |= ios_base::failbit;
439439
return false;
@@ -451,7 +451,7 @@ bool money_get<_CharT, _InputIterator>::__do_get(
451451
}
452452
}
453453
if (__trailing_sign) {
454-
for (unsigned __i = 1; __i < __trailing_sign->size(); ++__i, ++__b) {
454+
for (unsigned __i = 1; __i < __trailing_sign->size(); ++__i, (void)++__b) {
455455
if (__b == __e || *__b != (*__trailing_sign)[__i]) {
456456
__err |= ios_base::failbit;
457457
return false;

libcxx/include/__locale_dir/num.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,7 @@ num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, char_ty
885885
const numpunct<char_type>& __np = std::use_facet<numpunct<char_type> >(__iob.getloc());
886886
typedef typename numpunct<char_type>::string_type string_type;
887887
string_type __nm = __v ? __np.truename() : __np.falsename();
888-
for (typename string_type::iterator __i = __nm.begin(); __i != __nm.end(); ++__i, ++__s)
888+
for (typename string_type::iterator __i = __nm.begin(); __i != __nm.end(); ++__i, (void)++__s)
889889
*__s = *__i;
890890
return __s;
891891
}

libcxx/include/__locale_dir/pad_and_output.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ _LIBCPP_HIDE_FROM_ABI _OutputIterator __pad_and_output(
3030
__ns -= __sz;
3131
else
3232
__ns = 0;
33-
for (; __ob < __op; ++__ob, ++__s)
33+
for (; __ob < __op; ++__ob, (void)++__s)
3434
*__s = *__ob;
35-
for (; __ns; --__ns, ++__s)
35+
for (; __ns; --__ns, (void)++__s)
3636
*__s = __fl;
37-
for (; __ob < __oe; ++__ob, ++__s)
37+
for (; __ob < __oe; ++__ob, (void)++__s)
3838
*__s = *__ob;
3939
__iob.width(0);
4040
return __s;

libcxx/include/__random/piecewise_constant_distribution.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ piecewise_constant_distribution<_RealType>::param_type::param_type(
190190
__areas_.assign(1, 0.0);
191191
} else {
192192
__densities_.reserve(__b_.size() - 1);
193-
for (size_t __i = 0; __i < __b_.size() - 1; ++__i, ++__f_w)
193+
for (size_t __i = 0; __i < __b_.size() - 1; ++__i, (void)++__f_w)
194194
__densities_.push_back(*__f_w);
195195
__init();
196196
}

libcxx/include/__random/piecewise_linear_distribution.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ piecewise_linear_distribution<_RealType>::param_type::param_type(
194194
__areas_.assign(1, 0.0);
195195
} else {
196196
__densities_.reserve(__b_.size());
197-
for (size_t __i = 0; __i < __b_.size(); ++__i, ++__f_w)
197+
for (size_t __i = 0; __i < __b_.size(); ++__i, (void)++__f_w)
198198
__densities_.push_back(*__f_w);
199199
__init();
200200
}

libcxx/test/std/containers/sequences/deque/deque.cons/iter_iter.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ void test(InputIterator f, InputIterator l) {
3333
assert(d.size() == static_cast<std::size_t>(std::distance(f, l)));
3434
assert(static_cast<std::size_t>(std::distance(d.begin(), d.end())) == d.size());
3535
LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(d));
36-
for (const_iterator i = d.begin(), e = d.end(); i != e; ++i, ++f)
36+
for (const_iterator i = d.begin(), e = d.end(); i != e; ++i, (void)++f)
3737
assert(*i == *f);
3838
}
3939

libcxx/test/std/containers/sequences/deque/deque.cons/iter_iter_alloc.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void test(InputIterator f, InputIterator l, const Allocator& a) {
3434
assert(d.size() == static_cast<std::size_t>(std::distance(f, l)));
3535
assert(static_cast<std::size_t>(std::distance(d.begin(), d.end())) == d.size());
3636
LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(d));
37-
for (const_iterator i = d.begin(), e = d.end(); i != e; ++i, ++f)
37+
for (const_iterator i = d.begin(), e = d.end(); i != e; ++i, (void)++f)
3838
assert(*i == *f);
3939
}
4040

libcxx/test/std/containers/sequences/vector.bool/construct_iter_iter.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ TEST_CONSTEXPR_CXX20 void test(Iterator first, Iterator last) {
2424
C c(first, last);
2525
LIBCPP_ASSERT(c.__invariants());
2626
assert(c.size() == static_cast<std::size_t>(std::distance(first, last)));
27-
for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i, ++first)
27+
for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i, (void)++first)
2828
assert(*i == *first);
2929
}
3030

libcxx/test/std/containers/sequences/vector.bool/construct_iter_iter_alloc.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ TEST_CONSTEXPR_CXX20 void test(Iterator first, Iterator last, const typename C::
2525
C c(first, last, a);
2626
LIBCPP_ASSERT(c.__invariants());
2727
assert(c.size() == static_cast<std::size_t>(std::distance(first, last)));
28-
for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i, ++first)
28+
for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i, (void)++first)
2929
assert(*i == *first);
3030
}
3131

libcxx/test/std/containers/sequences/vector/vector.cons/construct_iter_iter.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ TEST_CONSTEXPR_CXX20 void test(Iterator first, Iterator last) {
3131
LIBCPP_ASSERT(c.__invariants());
3232
assert(c.size() == static_cast<std::size_t>(std::distance(first, last)));
3333
LIBCPP_ASSERT(is_contiguous_container_asan_correct(c));
34-
for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i, ++first)
34+
for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i, (void)++first)
3535
assert(*i == *first);
3636
}
3737
// Test with an empty range

0 commit comments

Comments
 (0)