Boost logo

Geometry :

Subject: [geometry] GCC 4.9.1 "may be used uninitialized" warnings
From: Patrick J. LoPresti (lopresti_at_[hidden])
Date: 2014-10-14 21:35:22


This is with Boost.Geometry 1.56.

When I compile the (short) appended program with "g++ -O3 -Wall
-Werror -Wno-unused-local-typedefs", I get warnings like this:

In file included from
.../boost/geometry/index/detail/rtree/visitors/insert.hpp:14:0,
                 from .../boost/geometry/index/rtree.hpp:61,
                 from bug.cc:1:
.../boost/geometry/index/detail/algorithms/content.hpp: In static
member function ‘static size_t
boost::geometry::index::detail::rtree::choose_next_node<...>
[... much template expansion elided ...]
.../boost/geometry/index/detail/algorithms/content.hpp:36:99: error:
‘*((void*)& box_intersection +24)’ may be used uninitialized in this
function [-Werror=maybe-uninitialized]
 _corner, CurrentDimension - 1>(b) - get<min_corner, CurrentDimension - 1>(b) );
                                                                              ^
In file included from
.../boost/geometry/index/detail/rtree/rstar/choose_next_node.hpp:19:0,
                 from .../boost/geometry/index/detail/rtree/rstar/rstar.hpp:15,
                 from .../boost/geometry/index/rtree.hpp:72,
                 from bug.cc:1:
.../boost/geometry/index/detail/algorithms/intersection_content.hpp:28:13:
note: ‘*((void*)& box_intersection +24)’ was declared here
         Box box_intersection;

The -Wno-unused-local-typedefs is needed to silence some warnings from
the Boost "ublas" module. The "may be used uninitialized" warnings are
originating from Boost.Geometry (I think).

Strangely, if I change the Point typedef to use int instead of double,
the warning goes away. Which makes me think this might be a compiler
bug (?), which is why I am asking here before I submit anything to
Trac.

...

OK, I think I see it. In
algorithms/detail/overlay/intersection_box_box.hpp, it looks like
apply() returns false early (without initializing box_out) when the
intervals do not intersect. But in
index/detail/algorithms/intersection_content.hpp, the return value of
geometry::intersection() is not checked, because the logic does not
require it:

    if ( geometry::intersects(box1, box2) )
    {
        Box box_intersection;
        geometry::intersection(box1, box2, box_intersection); //
return value ignored
        return detail::content(box_intersection);
    }
    return 0;

I have confirmed that the warning vanishes if I rewrite the code like this:

    Box box_intersection;
    if ( geometry::intersection(box1, box2, box_intersection) )
        return detail::content(box_intersection);
    return 0;

Are you folks amenable to this change to silence GCC, or do you fear
the performance implications?

 - Pat

#include <boost/geometry/index/rtree.hpp>

namespace bg = boost::geometry;
namespace bgi = bg::index;

int
main(int argc, char *argv[])
{
    typedef bg::model::point<double, 2, bg::cs::cartesian> Point;
    typedef bg::model::box<Point> Box;
    typedef std::pair<Box, int> Value;

    typedef bgi::rtree<Value, bgi::rstar<16> > RTree;

    RTree rtree;

    rtree.insert(std::make_pair(Box(Point(0,0), Point(1,1)), 0));
}


Geometry list run by mateusz at loskot.net