boostorg / polygon

Boost.org polygon module
http://boost.org/libs/polygon
57 stars 70 forks source link

Mark operators const #74

Closed fiesh closed 1 year ago

fiesh commented 2 years ago

These operators missing the const keyword made them incorrect code in C++20:

Let t.cpp be the following file:

#include <polygon.hpp>
using T = boost::polygon::poly_line_arbitrary_polygon_data<int>::iterator_holes_type;                                                                                         
bool f() { return T{} != T{}; }         

Then with clang-13:

% clang++ -std=c++20 -I polygon/include/boost/polygon -c t.cpp
t.cpp:6:23: warning: ISO C++20 considers use of overloaded operator '!=' (with operand types 'T' (aka 'boost::polygon::poly_line_arbitrary_polygon_data<int>::iterator_holes_type') and 'T') to be ambiguous despite there being a unique best viable function with non-reversed arguments [-Wambiguous-reversed-operator]
bool f() { return T{} != T{}; }
                  ~~~ ^  ~~~
polygon/include/boost/polygon/detail/polygon_arbitrary_formation.hpp:2179:19: note: candidate function with non-reversed arguments
      inline bool operator!=(const iterator_holes_type& that) { return itr_ != that.itr_; }
                  ^
polygon/include/boost/polygon/detail/polygon_arbitrary_formation.hpp:2178:19: note: ambiguous candidate function with reversed arguments
      inline bool operator==(const iterator_holes_type& that) { return itr_ == that.itr_; }
                  ^
1 warning generated.

Making the operators const resolves this issue.

fiesh commented 2 years ago

This in particular fixes polygon_set's resize and shrink operations with C++20 which don't compile otherwise. (With clang at least.)

fiesh commented 2 years ago

@asydorchuk I know this library is basically dead, but including such a simple pull request would be great since otherwise it is incompatible with C++20, a fact that just isn't caught by any test so far I suppose.