xg-old
xg-old copied to clipboard
XG does not compile with gcc7.1+matching glibc
As reported in gitter
deps/xg/src/xg.cpp: In member function ‘int xg::XG::min_distance_in_paths(int64_t, bool, size_t, int64_t, bool, size_t) const’:
deps/xg/src/xg.cpp:2348:22: error: call of overloaded ‘abs(long unsigned int&)’ is ambiguous
if (abs(o) < abs(min_dist)) {
I also came here to report this. :)
Actually the type of o
is size_t
(a.k.a unsigned long int
) which is unsigned and abs(o)
does not make any sense. There are two ways for workaround:
- Remove
abs
function call and replace it by simplyo
.
diff --git a/src/xg.cpp b/src/xg.cpp
index de702bf..78a6a32 100644
--- a/src/xg.cpp
+++ b/src/xg.cpp
@@ -2450,7 +2450,7 @@ int XG::min_distance_in_paths(int64_t id1, bool is_rev1, size_t offset1,
int min_dist = std::numeric_limits<int>::max();
for (auto& c : dist) {
for (auto& o : c.second) {
- if (abs(o) < abs(min_dist)) {
+ if (o < abs(min_dist)) {
min_dist = o;
}
}
- or cast
o
to typestd::intmax_t
which is the largest possible integer type:
diff --git a/src/xg.cpp b/src/xg.cpp
index de702bf..78a6a32 100644
--- a/src/xg.cpp
+++ b/src/xg.cpp
@@ -2450,7 +2450,7 @@ int XG::min_distance_in_paths(int64_t id1, bool is_rev1, size_t offset1,
int min_dist = std::numeric_limits<int>::max();
for (auto& c : dist) {
for (auto& o : c.second) {
- if (abs(o) < abs(min_dist)) {
+ if (abs(static_cast<std::intmax_t>(o)) < abs(min_dist)) {
min_dist = o;
}
}
The latter ensures that the expression is always non-negative even if the type of o
would change to a signed type in future.
This has been fixed. But please note that xg now lives in vg, so the current version is here:
https://github.com/vgteam/vg/blob/master/src/xg.cpp
On Tue, Sep 26, 2017 at 9:40 AM, Ali Ghaffaari [email protected] wrote:
I came here to report this. Actually the type of o is size_t (a.k.a unsigned long int) which is unsigned and abs(o) does not make any sense. There are two ways for workaround:
Make abs function call and replace it by simply o:
if (o < abs(min_dist)) {
or cast it to std::intmax_t which is the largest possible integer type:
if (abs(static_cast<std::intmax_t>(o)) < abs(min_dist)) {
The latter ensures the expression is always non-negative even if the type of o would change to a signed type in future.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/vgteam/xg/issues/68#issuecomment-332201421, or mute the thread https://github.com/notifications/unsubscribe-auth/AA2_7mJyus4DQcwhkAuWKG4V4Daas-ZHks5smP7SgaJpZM4PR6q3 .
I didn't know that. Thanks for mentioning. How about 'libxg'?
Gone
On Tue, Sep 26, 2017 at 10:01 AM, Ali Ghaffaari [email protected] wrote:
I didn't know that. Thanks for mentioning. How about 'libxg'?
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/vgteam/xg/issues/68#issuecomment-332207907, or mute the thread https://github.com/notifications/unsubscribe-auth/AA2_7pmwjkPBlwKrJc6gGRXIvJqejosTks5smQO5gaJpZM4PR6q3 .