Boost C++ Libraries: Ticket #2669: Boost 1.37 breaks spirit iterator differencing https://svn.boost.org/trac10/ticket/2669 <p> Attached minimal test file compiles fine under Boost v1.35, but fails to compile with Boost v1.37 (from Macports) and Darwin gcc 4.0.1. The problem has also been noted on other OS's with our software. </p> <p> The commented out <code>iterator_difference</code> attempt fails in the same manner with v1.37. </p> <pre class="wiki">$ gcc -o test-iter.o -c /z/o/test-iter.cpp -I/opt/local/include /opt/local/include/boost/iterator/iterator_adaptor.hpp: In function ‘void boost::detail::iterator_adaptor_assert_traversal() [with Tr1 = boost::forward_traversal_tag, Tr2 = boost::random_access_traversal_tag]’: /opt/local/include/boost/iterator/iterator_adaptor.hpp:353: instantiated from ‘typename boost::detail::iterator_adaptor_base&lt;Derived, Base, Value, Traversal, Reference, Difference&gt;::type::difference_type boost::iterator_adaptor&lt;Derived, Base, Value, Traversal, Reference, Difference&gt;::distance_to(const boost::iterator_adaptor&lt;OtherDerived, OtherIterator, V, C, R, D&gt;&amp;) const [with OtherDerived = boost::spirit::position_iterator&lt;__gnu_cxx::__normal_iterator&lt;char*, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, boost::spirit::file_position_base&lt;std::string&gt;, boost::spirit::nil_t&gt;, OtherIterator = __gnu_cxx::__normal_iterator&lt;char*, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, V = const char, C = boost::forward_traversal_tag, R = boost::use_default, D = boost::use_default, Derived = boost::spirit::position_iterator&lt;__gnu_cxx::__normal_iterator&lt;char*, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, boost::spirit::file_position_base&lt;std::string&gt;, boost::spirit::nil_t&gt;, Base = __gnu_cxx::__normal_iterator&lt;char*, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, Value = const char, Traversal = boost::forward_traversal_tag, Reference = boost::use_default, Difference = boost::use_default]’ /opt/local/include/boost/iterator/iterator_facade.hpp:553: instantiated from ‘static typename Facade1::difference_type boost::iterator_core_access::distance_from(const Facade1&amp;, const Facade2&amp;, mpl_::true_) [with Facade1 = boost::spirit::position_iterator&lt;__gnu_cxx::__normal_iterator&lt;char*, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, boost::spirit::file_position_base&lt;std::string&gt;, boost::spirit::nil_t&gt;, Facade2 = boost::spirit::position_iterator&lt;__gnu_cxx::__normal_iterator&lt;char*, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, boost::spirit::file_position_base&lt;std::string&gt;, boost::spirit::nil_t&gt;]’ /opt/local/include/boost/iterator/iterator_facade.hpp:846: instantiated from ‘typename boost::detail::enable_if_interoperable&lt;Derived1, Derived2, typename boost::mpl::apply2&lt;boost::detail::choose_difference_type, Derived1, Derived2&gt;::type&gt;::type boost::operator-(const boost::iterator_facade&lt;Derived1, V1, TC1, Reference1, Difference1&gt;&amp;, const boost::iterator_facade&lt;Derived2, V2, TC2, Reference2, Difference2&gt;&amp;) [with Derived1 = boost::spirit::position_iterator&lt;__gnu_cxx::__normal_iterator&lt;char*, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, boost::spirit::file_position_base&lt;std::string&gt;, boost::spirit::nil_t&gt;, V1 = const char, TC1 = boost::forward_traversal_tag, Reference1 = const char&amp;, Difference1 = ptrdiff_t, Derived2 = boost::spirit::position_iterator&lt;__gnu_cxx::__normal_iterator&lt;char*, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, boost::spirit::file_position_base&lt;std::string&gt;, boost::spirit::nil_t&gt;, V2 = const char, TC2 = boost::forward_traversal_tag, Reference2 = const char&amp;, Difference2 = ptrdiff_t]’ /z/o/test-iter.cpp:10: instantiated from here /opt/local/include/boost/iterator/iterator_adaptor.hpp:230: error: invalid application of ‘sizeof’ to incomplete type ‘boost::STATIC_ASSERTION_FAILURE&lt;false&gt;’ </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/2669 Trac 1.4.3 S Roderick <kiwi.net@…> Wed, 21 Jan 2009 15:06:22 GMT attachment set https://svn.boost.org/trac10/ticket/2669 https://svn.boost.org/trac10/ticket/2669 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">test-iter.cpp</span> </li> </ul> Ticket Daniel James Wed, 21 Jan 2009 15:28:28 GMT attachment set https://svn.boost.org/trac10/ticket/2669 https://svn.boost.org/trac10/ticket/2669 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">iter-difference.cpp</span> </li> </ul> <p> Demonstration of problem with boost 1.35 </p> Ticket Daniel James Wed, 21 Jan 2009 15:31:09 GMT <link>https://svn.boost.org/trac10/ticket/2669#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2669#comment:1</guid> <description> <p> <code>position_iterator</code> was always meant to be a forward iterator and only had a difference operator by mistake, which didn't work in many cases (I've just attached an example which gives an incorrect result with boost 1.35, operator- also gives incorrect results if the string contains windows newlines). There are two possible fixes: the safe, but slow way, is to use std::difference, or if you're sure that both iterators contain a valid iterator (they haven't been default constructed, and have been constructed with an iterator from the same container) then you can access the underlying iterator using the <code>base</code> method - <code>end.base() - begin.base()</code>. </p> </description> <category>Ticket</category> </item> <item> <author>S Roderick <kiwi.net@…></author> <pubDate>Wed, 21 Jan 2009 18:06:44 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/2669#comment:2 https://svn.boost.org/trac10/ticket/2669#comment:2 <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">invalid</span> </li> </ul> <p> We can use the <code>base()</code> method for our purposes. Thanks, consider this resolved. </p> Ticket