geometry
geometry copied to clipboard
MSVC Warning: C4244 'initializing': conversion from 'CoordinateType' to 'const PromotedType', possible loss of data
Minimal Code to produce related warning (boost 1.70.0 MSVC 2017 15.8.0 /std:c++latest /W4):
boost::geometry::model::polygon<
boost::geometry::model::point<std::int64_t, 3, boost::geometry::cs::cartesian>
> test;
boost::geometry::remove_spikes(test);
If the std::int64_t
in the above is changed to int
there is no warning.
On line 245 (side_by_triangle.hpp) boost decides the type of PromotedType = select_most_precise<double,std::int64_t>
=> double
. And then initializes PromotedType values with std::int64_t
values.
This pattern of select_most_precise<double,...> is pretty common, and I have found the same warning being produced in other parts of boost that do the same thing when using with std::int64_t
.
This is still a problem in boost 1.72.0.
\boost_1_72_0\boost\geometry\strategies\cartesian\side_by_triangle.hpp(123): error C4244: 'initializing': conversion from 'CoordinateType' to 'PromotedType', possible loss of data
This is still a problem in boost 1.73.0.
\boost_1_73_0\boost\geometry\strategies\cartesian\side_by_triangle.hpp(123): error C4244: 'initializing': conversion from 'CoordinateType' to 'PromotedType', possible loss of data
I think it should be safe to ... = static_cast<PromotedType>(...)
wherever the left-hand side is an explicitly promoted type.
@awulkiew What do you think?
Hello, I have a similar problem on Windows using msvc14.1. On linux there is no warning by the way.
I created a minimal example:
#include <boost/geometry.hpp>
namespace bg = boost::geometry;
typedef bg::model::polygon<bg::model::d2::point_xy<double>> polygon_t;
typedef bg::model::multi_polygon<polygon_t> mpolygon_t;
int main() {
polygon_t p0{ {{-5,-5},{-5,5},{5,5},{5,-5},{-5,-5}} };
polygon_t p1{ {{-4,-4},{-4,4},{4,4},{4,-4},{-4,-4}} };
mpolygon_t out;
bg::difference(p0, p1, out);
}
I than tracked it back to point_is_spike_or_equal.hpp
line 142-146 and added the following lines to get some debugging output:
static_assert(Point1::foo);
static_assert(robust_point_type::foo);
And got the following errors:
1>...\boost\geometry\algorithms\detail\point_is_spike_or_equal.hpp(148): error C2039: 'foo': is not a member of 'boost::geometry::model::d2::point_xy<double,boost::geometry::cs::cartesian>'
1>...\consoleapplication1.cpp(9): note: see declaration of 'boost::geometry::model::d2::point_xy<double,boost::geometry::cs::cartesian>'
1>...\boost\geometry\algorithms\detail\point_is_spike_or_equal.hpp(148): error C2065: 'foo': undeclared identifier
1>...\boost\geometry\algorithms\detail\point_is_spike_or_equal.hpp(149): error C2039: 'foo': is not a member of 'boost::geometry::model::point<__int64,2,boost::geometry::cs::cartesian>'
1>...\boost\geometry\policies\robustness\get_rescale_policy.hpp(188): note: see declaration of 'boost::geometry::model::point<__int64,2,boost::geometry::cs::cartesian>'
1>...\boost\geometry\algorithms\detail\point_is_spike_or_equal.hpp(149): error C2065: 'foo': undeclared identifier
Where the 4th line is the interesting one. Why is the coordinate_type
of boost::geometry::model::point
an __int64
. robust_point_type::type
should have the same type as Point1
in the 2nd line.
This is still a problem in 1.75.0.
\boost_1_75_0\boost\geometry\strategies\cartesian\side_by_triangle.hpp(123,37): error C4244: 'initializing': conversion from 'CoordinateType' to 'PromotedType', possible loss of data
This is still a problem in 1.79.0.
\boost_1_79_0\boost\geometry\strategy\cartesian\side_by_triangle.hpp(102,37): warning C4244: 'initializing': conversion from 'CoordinateType' to 'PromotedType', possible loss of data
Seems unmaintained.
This is still a problem in 1.83.0.
boost_1_83_0\boost\geometry\strategy\cartesian\side_by_triangle.hpp(103,37): error C4244: 'initializing': conversion from 'CoordinateType' to 'PromotedType', possible loss of data
still problem in 1.84.0
boost_1_84_0\boost\range\irange.hpp(168,32): warning C4244: 'return': conversion from '__int64' to 'int', possible loss of data