vendredi 23 janvier 2015

Different compiler behavior with C++11

The following code



#include <vector>
#include <complex>
#include <algorithm>

template<class K>
inline void conjVec(int m, K* const in) {
if(!std::is_same<typename std::remove_pointer<K>::type, double>::value)
#ifndef OK
std::for_each(in, in + m, [](K& z) { z = std::conj(z); });
#else
std::for_each(reinterpret_cast<std::complex<double>*>(in), reinterpret_cast<std::complex<double>*>(in) + m, [](std::complex<double>& z) { z = std::conj(z); });
#endif
}

int main(int argc, char* argv[]) {
std::vector<double> nums;
nums.emplace_back(1.0);
conjVec(nums.size(), nums.data());
return 0;
}


compiles fine on Linux with



  1. Debian clang version 3.5.0-9

  2. gcc version 4.9.1

  3. icpc version 15.0.1


and on Mac OS X with



  1. gcc version 4.9.2


but not with



  1. clang-600.0.56

  2. icpc version 15.0.1


except if the macro OK is defined. I don't know which are the faulty compilers, could someone let me know ? Thanks.


Aucun commentaire:

Enregistrer un commentaire