Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use of boost::reversed_iterator within boost::reversed_range adaptor #135

Open
smitsyn opened this issue May 31, 2022 · 1 comment
Open

Comments

@smitsyn
Copy link

smitsyn commented May 31, 2022

We use custom span class template, and it works incorrectly with boost::adapters::reverse. Link to reproduce:

https://godbolt.org/z/1Yxvqvj4r

Executable compiled with clang prints incorrect value, with gcc - exits with nonzero code, and msvc compiler emits a warning. I believe godbolt doesn't support sanitizers ATM. Non-const span is provided and works fine.

I believe the problem is that iterator_range::operator[] returns by reference and uses boost::reverse_iterator::operator[], but the latter reserved a right to return by value. According to docs ( https://www.boost.org/doc/libs/1_79_0/libs/iterator/doc/reverse_iterator.html ) it is "Random Access Iterator", and according to other docs ( https://www.boost.org/doc/libs/1_79_0/libs/iterator/doc/new-iter-concepts.html#design ), "operator[] is only required to return something convertible to the value_type (for a Readable Iterator)", which reverse_iterator does ( https://www.boost.org/doc/libs/1_79_0/libs/iterator/doc/new-iter-concepts.html#random-access-traversal-iterators-lib-random-access-traversal-iterators ): "a[n] has return type convertible to T" (for random access iterator as defined in now quite old "New Iterator Concepts").

Note that some std::reverse_iterator implementations return by reference in const T case too and could work with boost::iterator_range.

@smitsyn
Copy link
Author

smitsyn commented May 31, 2022

When #122 is merged, this could fail with std::span too.

@smitsyn smitsyn changed the title boost::reversed_iterator possibly shouldn't be used in boost::reversed_range adaptor use of boost::reversed_iterator within boost::reversed_range adaptor May 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant