Boost C++ Libraries: Ticket #5162: boost::iterator_range< T* > is unsafe https://svn.boost.org/trac10/ticket/5162 <p> The following code compiles and does not generate any warning: </p> <pre class="wiki">#include &lt;boost/range/iterator_range.hpp&gt; int main() { double v[] = { 1.0,2.0,3.0 }; boost::iterator_range&lt;float *&gt; r = boost::make_iterator_range( v ); } </pre><p> The culprits are adl_begin, adl_end, as in this case, they perform a C-style cast from double* to float*: </p> <pre class="wiki"> template&lt;class IteratorT&gt; struct iterator_range_impl { template&lt; class ForwardRange &gt; static IteratorT adl_begin( ForwardRange&amp; r ) { return IteratorT( boost::begin( r ) ); } template&lt; class ForwardRange &gt; static IteratorT adl_end( ForwardRange&amp; r ) { return IteratorT( boost::end( r ) ); } }; </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/5162 Trac 1.4.3 Neil Groves Sat, 02 Apr 2011 13:07:48 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/5162#comment:1 https://svn.boost.org/trac10/ticket/5162#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> 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. </p> Ticket