bioinfologics/w2rap-contigger

fails to compile with gcc 7.2.0

wookietreiber opened this issue · 2 comments

tested compilers

The compiler I used (current Arch Linux):

$ gcc --version
gcc (GCC) 7.2.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

I suppose, other GCC versions, i.e. 7+, are affected as well, because GCC changes default compiler flags between major releases. At another system, I compiled using a GCC from the 6 series and there were no problems:

$ gcc --version
gcc (GCC) 6.2.0
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

error messages

The error is this one:

$ make
Scanning dependencies of target hb_base_libs
[  0%] Building CXX object CMakeFiles/hb_base_libs.dir/src/paths/long/VariantCallTools.cc.o
/home/wookietreiber/src/idiv/w2rap-contigger/src/paths/long/VariantCallTools.cc: In member function ‘void EdgesOnRef::FilterAndModifyEdits(vec<triple<int, int, FeudalString<char> > >&, vec<std::pair<FeudalString<char>, FeudalString<char> > >&)’:
/home/wookietreiber/src/idiv/w2rap-contigger/src/paths/long/VariantCallTools.cc:1872:47: error: call of overloaded ‘abs(FeudalString<char>::size_type)’ is ambiguous
                     - change[j-1].first.size()) < MinClumpSep) {
                                               ^
In file included from /usr/include/c++/7.2.0/cstdlib:75:0,
                 from /usr/include/c++/7.2.0/ext/string_conversions.h:41,
                 from /usr/include/c++/7.2.0/bits/basic_string.h:6159,
                 from /usr/include/c++/7.2.0/string:52,
                 from /usr/include/c++/7.2.0/bits/locale_classes.h:40,
                 from /usr/include/c++/7.2.0/bits/ios_base.h:41,
                 from /usr/include/c++/7.2.0/iomanip:40,
                 from /home/wookietreiber/src/idiv/w2rap-contigger/src/system/System.h:13,
                 from /home/wookietreiber/src/idiv/w2rap-contigger/src/CoreTools.h:17,
                 from /home/wookietreiber/src/idiv/w2rap-contigger/src/paths/long/VariantCallTools.h:11,
                 from /home/wookietreiber/src/idiv/w2rap-contigger/src/paths/long/VariantCallTools.cc:12:
/usr/include/stdlib.h:722:12: note: candidate: int abs(int)
 extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
            ^~~
In file included from /usr/include/c++/7.2.0/cstdlib:77:0,
                 from /usr/include/c++/7.2.0/ext/string_conversions.h:41,
                 from /usr/include/c++/7.2.0/bits/basic_string.h:6159,
                 from /usr/include/c++/7.2.0/string:52,
                 from /usr/include/c++/7.2.0/bits/locale_classes.h:40,
                 from /usr/include/c++/7.2.0/bits/ios_base.h:41,
                 from /usr/include/c++/7.2.0/iomanip:40,
                 from /home/wookietreiber/src/idiv/w2rap-contigger/src/system/System.h:13,
                 from /home/wookietreiber/src/idiv/w2rap-contigger/src/CoreTools.h:17,
                 from /home/wookietreiber/src/idiv/w2rap-contigger/src/paths/long/VariantCallTools.h:11,
                 from /home/wookietreiber/src/idiv/w2rap-contigger/src/paths/long/VariantCallTools.cc:12:
/usr/include/c++/7.2.0/bits/std_abs.h:56:3: note: candidate: long int std::abs(long int)
   abs(long __i) { return __builtin_labs(__i); }
   ^~~
/usr/include/c++/7.2.0/bits/std_abs.h:61:3: note: candidate: long long int std::abs(long long int)
   abs(long long __x) { return __builtin_llabs (__x); }
   ^~~
/usr/include/c++/7.2.0/bits/std_abs.h:70:3: note: candidate: constexpr double std::abs(double)
   abs(double __x)
   ^~~
/usr/include/c++/7.2.0/bits/std_abs.h:74:3: note: candidate: constexpr float std::abs(float)
   abs(float __x)
   ^~~
/usr/include/c++/7.2.0/bits/std_abs.h:78:3: note: candidate: constexpr long double std::abs(long double)
   abs(long double __x)
   ^~~
make[2]: *** [CMakeFiles/hb_base_libs.dir/build.make:3111: CMakeFiles/hb_base_libs.dir/src/paths/long/VariantCallTools.cc.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:68: CMakeFiles/hb_base_libs.dir/all] Error 2
make: *** [Makefile:130: all] Error 2

analysis / probable fix

As far as I can tell, the ambiguity can be resolved, across all compiler versions, by explicitly casting the expression inside the abs call to the correct type, e.g.:

@@ -1868,8 +1868,8 @@ void EdgesOnRef::FilterAndModifyEdits( vec<triple<int,int,String>>& edits,
         bool i_is_indel = (change[i].first.size() != change[i].second.size());
         if (i_is_indel) inserted_base += change[i].second.size()-1;
         size_t j = i + 1;
-        while (j < edits.size() && abs(edits[j].second - edits[j-1].second 
-                    - change[j-1].first.size()) < MinClumpSep) {
+        while (j < edits.size() && abs((long double)(edits[j].second - edits[j-1].second 
+                    - change[j-1].first.size()) < MinClumpSep)) {
             nmatch += edits[j].second - edits[j-1].second - change[j-1].first.size();
             bool j_is_indel = (change[j].first.size() != change[j].second.size());
             if (j_is_indel) 

Useful:

Note: I used long double here just to get it to compile and to test #30, don't know if that's the correct type. I didn't want to look at the codebase in depth to figure it out, but you surely can ;)

An alternative solution is editing the make to not include the variant calling sources given that they aren't required to generate the contigs. We have done that on the latest but unstable branch.

Just in case this would be helpful, I was able to install w2rap-contigger by installing gcc6 using conda:

conda create -n w2rap -c omgarcia gcc-6
conda activate w2rap

cmake -D CMAKE_CXX_COMPILER=g++ .
make -j 4