mercredi 4 octobre 2017

Compiling std::transforms with argument atan2/pow fails with clang (but works with gcc)

There seem to be some difference in how template parameters are resolved for clang and gcc. Or maybe clang does not consider atan2 and pow binary operations but gcc does.

The code sample below does not make much sense on its own but recreates the issue in a minimal fashion:

#include <cmath>
#include <vector>
#include <algorithm>

int main() 
    std::vector<float> a;
    std::vector<float> b;
    std::vector<float> dst;
    std::transform(a.begin(), a.end(), b.begin(), dst.begin(), ::atan2);
    return 0;
}

Compiling this with GCC (5.4 Ubuntu; 6.0 OSX Sierra) works fine. Using clang (900.0.37) returns the following error:

/Applications/http://ift.tt/1qM1lu4    -g   -std=gnu++11 -o CMakeFiles/http://ift.tt/2xSSAYB -c /Users/../CLionProjects/temptest/main.cpp
/Users/../CLionProjects/temptest/main.cpp:9:5: error: no matching function for call to 'transform'
    std::transform(a.begin(), a.end(), b.begin(), dst.begin(), ::atan2);
    ^~~~~~~~~~~~~~
/Applications/http://ift.tt/2ga12Ze: note: candidate template ignored: couldn't infer template argument '_BinaryOperation'
transform(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2,
^
/Applications/http://ift.tt/2xSSBvD: note: candidate function template not viable: requires 4 arguments, but 5 were provided
transform(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _UnaryOperation __op)
^
1 error generated.

I am pretty sure that the first version (line 1932) is the correct template but somehow clang 'fails' to resolve ::atan2 as a BinaryOperation (which gcc does). I am also quite certain that this 'used to work' with older versions of XCode and/or OSX versions since the related code hasn't been changed in 5 years.

Aucun commentaire:

Enregistrer un commentaire