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

UB instead of compile error when using any_range with Reference = T const & #99

Open
allopislozano opened this issue Dec 13, 2019 · 0 comments

Comments

@allopislozano
Copy link

https://godbolt.org/z/b_YJ_L

This issue was already reported in https://svn.boost.org/trac10/ticket/10493

It looks like the issue is still in 1.71.
I would expect that range_t_2 would fail to compile. The designer of any_iterator_range wrote an article about type erasure https://www.artima.com/cppsource/type_erasure.html where he mentions that:

However, if we try to assign to our number iterator a transform iterator which, upon dereferencing, multiplies by 100.0, we run into trouble.

number_it = boost::make_transform_iterator(
number_vector.begin(),
boost::bind(std::multiplies(), _1, 100)
);

My any_iterator's assignment operator is not enabled for this assignment, and you will get an error message such as:
binary '=': no operator found which takes a right-hand operand of type...

I think this is what should happen in the case of range_t_2 in my example, so that you can use const & as reference_type and you know that if someone tries to assign a transform_iterator or any other iterator that returns temporaries he will get a compiler error.

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