Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MSVC Warning: C4244 'initializing': conversion from 'CoordinateType' to 'const PromotedType', possible loss of data #629

Open
AlastairHolmes opened this issue Oct 24, 2019 · 9 comments
Labels
good-first-issue What new contributors may find easy to start with and improve Geometry warning

Comments

@AlastairHolmes
Copy link

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.

@mloskot mloskot added the good-first-issue What new contributors may find easy to start with and improve Geometry label Feb 27, 2020
@vschoech
Copy link

vschoech commented Mar 9, 2020

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

@vschoech
Copy link

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

@mloskot
Copy link
Member

mloskot commented Jun 18, 2020

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?

@Ne94fets
Copy link

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.

@vschoech
Copy link

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

@wanghan02
Copy link

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

@yoavmil
Copy link

yoavmil commented Jul 6, 2022

Seems unmaintained.

@wanghan02
Copy link

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

@leewi9
Copy link

leewi9 commented Mar 5, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good-first-issue What new contributors may find easy to start with and improve Geometry warning
Projects
None yet
Development

No branches or pull requests

7 participants