Skip to content

Ring iterators required to return references to points, otherwise dangling references happen #716

@autc04

Description

@autc04

According to my reading of the documentation, iterators for the vertices of an adapted ring type are allowed to return any type convertible to T from their operator*().

However, linear_segment_or_box.hpp, line 101 constructs a referring_segment from dereferenced iterators into a ring:

                range_segment rng_segment(*it0, *it1);

where range_segment is defined as:

 typedef typename geometry::model::referring_segment
            <
                point_type const
            > range_segment;

If the return value of *it0 and *it1 is anything but a point_type& or a const point_type&, this silently constructs a dangling reference to a temporary, leading to hard-to-debug failures.

The documentation for the ring concept refers to the Boost.Range Random Access Range concept, which says that the iterators must be Random Access Traversal Iteratos. There, the only requirement on the return type of *a is that it is
"Convertible to T".

Requiring the return type to be (const) point_type&, besides being currently undocumented, precludes writing adapters for types where the points are not stored explicitly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions