xg-old icon indicating copy to clipboard operation
xg-old copied to clipboard

XG does not compile with gcc7.1+matching glibc

Open JervenBolleman opened this issue 7 years ago • 4 comments

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)) {

JervenBolleman avatar Sep 09 '17 07:09 JervenBolleman

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:

  1. Remove abs function call and replace it by simply o.
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;
             }
         }
  1. or cast o to type std::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.

cartoonist avatar Sep 26 '17 13:09 cartoonist

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 .

glennhickey avatar Sep 26 '17 13:09 glennhickey

I didn't know that. Thanks for mentioning. How about 'libxg'?

cartoonist avatar Sep 26 '17 14:09 cartoonist

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 .

glennhickey avatar Sep 26 '17 14:09 glennhickey