Opened 12 years ago
Closed 12 years ago
#5162 closed Bugs (fixed)
boost::iterator_range< T* > is unsafe
Reported by: | Owned by: | Neil Groves | |
---|---|---|---|
Milestone: | To Be Determined | Component: | range |
Version: | Boost 1.45.0 | Severity: | Problem |
Keywords: | Cc: |
Description
The following code compiles and does not generate any warning:
#include <boost/range/iterator_range.hpp> int main() { double v[] = { 1.0,2.0,3.0 }; boost::iterator_range<float *> r = boost::make_iterator_range( v ); }
The culprits are adl_begin, adl_end, as in this case, they perform a C-style cast from double* to float*:
template<class IteratorT> struct iterator_range_impl { template< class ForwardRange > static IteratorT adl_begin( ForwardRange& r ) { return IteratorT( boost::begin( r ) ); } template< class ForwardRange > static IteratorT adl_end( ForwardRange& r ) { return IteratorT( boost::end( r ) ); } };
Note:
See TracTickets
for help on using tickets.
Resolved on the trunk by simply altering the code to use static_cast. Additional tests were added to ensure scenarios like those provided do not compile, while other compatible pointers continue to work as expected.