diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2021-06-15 15:07:25 +0100 |
---|---|---|
committer | Jonathan Wakely <jwakely@redhat.com> | 2021-06-15 18:20:06 +0100 |
commit | a88fc03ba7e52d9a072f25d42bb9619fedb7892e (patch) | |
tree | 854d23ea74bfc34c1b755753186904c893b1a3c7 /gcc | |
parent | cb326a6442f09cb36b05ce556fc91e10bfeb0cf6 (diff) | |
download | gcc-a88fc03ba7e52d9a072f25d42bb9619fedb7892e.zip gcc-a88fc03ba7e52d9a072f25d42bb9619fedb7892e.tar.gz gcc-a88fc03ba7e52d9a072f25d42bb9619fedb7892e.tar.bz2 |
libstdc++: Remove precondition checks from ranges::subrange
The assertion in the subrange constructor causes semantic changes,
because the call to ranges::distance performs additional operations that
are not part of the constructor's specification. That will fail to
compile if the iterator is move-only, because the argument to
ranges::distance is passed by value. It will modify the subrange if the
iterator is not a forward iterator, because incrementing the copy also
affects the _M_begin member. Those problems could be prevented by using
if-constexpr to only do the assertion for copyable forward iterators,
but the call to ranges::distance can also prevent the constructor being
usable in constant expressions. If the member initializers are usable in
constant expressions, but iterator increments of equality comparisons
are not, then the checks done by __glibcxx_assert might
make constant evaluation fail.
This change removes the assertion. Additionally, a new typedef is
introduced to simplify the declarations using __make_unsigned_like_t on
the iterator's difference type.
Signed-off-by: Jonathan Wakely <jwakely@redhat.com>
libstdc++-v3/ChangeLog:
* include/bits/ranges_util.h (subrange): Add __size_type typedef
and use it to simplify declarations.
(subrange(i, s, n)): Remove assertion.
* testsuite/std/ranges/subrange/constexpr.cc: New test.
Diffstat (limited to 'gcc')
0 files changed, 0 insertions, 0 deletions