Skip to content

Issue with assignment of an object_iterator to const_object_iterator using empty object #372

@danielaparker

Description

@danielaparker

Discussed in #368

Originally posted by awolff64 May 19, 2022
We have a strange problem that only happens with XCode on OSX. It works fine on Window and Linux.

We have an empty object assigning the result of a find() to a const_object_iterator. This should be the object's end().
The subsequent check for end() is not true and later on we run into problems because we assume the iterator is valid.

   Json::const_object_iterator it;

it = m_Definition.find("Min");

    if (it == m_Definition.object_range().end())
    {
          ...
    }

Our findings:
The iterator returned by find has has_value_ set to false.
The constructed const_iterator hat a has value of true.
=> comparison fails

We changed the random_access_iterator_wrapper (with less than partial understanding) to init has_value_ from the the other:

template <class Iter, class=typename std::enable_if<!std::is_same<Iter,Iterator>::value && std::is_convertible<Iter,Iterator>::value>::type> random_access_iterator_wrapper(const random_access_iterator_wrapper<Iter>& other) : it_(other.it_), has_value_(other.has_value_) { }
=> now it works.

Can anybody help on this?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions