Opened 11 years ago

Closed 11 years ago

#6714 closed Bugs (fixed)

utree::insert return begin() if position == end()

Reported by: sairony@… Owned by: Joel de Guzman
Milestone: To Be Determined Component: spirit
Version: Boost 1.48.0 Severity: Problem
Keywords: Cc:

Description

This seems intentional by looking at the source, but it makes utree::insert differ from stl in a subtle and very dangerous way. It also makes using insert excessively cumbersome, as you need to special case for position == end. Offending function is at BOOST/SPIRIT/HOME/SUPPORT/UTREE/DETAIL/UTREE_DETAIL2.HPP @ ~1037 ( inline utree::iterator utree::insert(iterator pos, T const& val) ).

Change History (3)

comment:1 by Joel de Guzman, 11 years ago

That's incorrect. Insert only returns begin() IF position == end() AND the container is empty. There is nothing wrong with the logic as it is. If you don't agree, feel free to attach a test case that proves that the logic is wrong. Please do so ASAP. I do not want to have lingering open issues. Thanks.

comment:2 by anonymous, 11 years ago

That does not seem to be the case. The following fails for me:

#include "boost/spirit/home/support/utree.hpp"
#include <cassert>
int main()
{
	boost::spirit::utree ut;
	ut.push_back(1);
	assert( ut.insert( ut.end(), 1 ) != ut.begin() );
}

If one takes a look at boost::utree::end() it creates an iterator with 0 as node ( makes sense I presume ). The guard is then:

if (!pos.node) 
{
        l.push_back(val);
        return utree::iterator(l.first, 0); // begin();
}

As pos.node == 0 for all end() it would seem it doesn't matter how many items are in the utree. Perhaps I'm missing something?

comment:3 by Joel de Guzman, 11 years ago

Resolution: fixed
Status: newclosed

No, you are right and I am blind! Fixed in trunk. Please verify; tests added.

Note: See TracTickets for help on using tickets.