icpc 13.0 cannot compile GCC 4.7 <complex> header in C++11 mode

icpc 13.0 cannot compile GCC 4.7 <complex> header in C++11 mode

When compiling the following simple test file, #include int main () { std::complex a(1, 1); double r = std::real(a); double i = std::imag(a); return 0; } With icpc -std=c++11 on RHEL 6.3 with GCC4.7 installed as the default GCC (g++ --version shows 4.7.1), the following error messages are emitted, $ icpc -std=c++11 -o foo foo.cpp /opt/gcc/include/c++/4.7.1/complex(536): error: no instance of overloaded function "std::complex::real" matches the argument list and object (the object has cv-qualifiers that prevent a match) object type is: const std::complex { return __z.real(); } ^ detected during instantiation of "_Tp std::real(const std::complex &) [with _Tp=double]" at line 6 of "foo.cpp" /opt/gcc/include/c++/4.7.1/complex(541): error: no instance of overloaded function "std::complex::imag" matches the argument list and object (the object has cv-qualifiers that prevent a match) object type is: const std::complex { return __z.imag(); } ^ detected during instantiation of "_Tp std::imag(const std::complex &) [with _Tp=double]" at line 7 of "foo.cpp" The relevant GCC header is as below. #ifdef __GXX_EXPERIMENTAL_CXX0X__ // _GLIBCXX_RESOLVE_LIB_DEFECTS // DR 387. std::complex over-encapsulated. constexpr _Tp- real() { return _M_real; } constexpr _Tp- imag() { return _M_imag; } #else /// Return real part of complex number. _Tp&- real() { return _M_real; } /// Return real part of complex number. const _Tp&- real() const { return _M_real; } /// Return imaginary part of complex number. _Tp&- imag() { return _M_imag; } /// Return imaginary part of complex number. const _Tp&- imag() const { return _M_imag; } #endif It seems icpc insists on the const version of the member functions while GCC4.7's version only provide them in the non-C++11 mode. I am not familiar with the standard. Is this a bug of icpc or GCC header? g++ can compile the above file without any problem.

3 帖子 / 0 全新
最新文章
如需更全面地了解编译器优化,请参阅优化注意事项

I have reduced the error to the following:

struct complex
{
// constexpr implies the function is a const member function
constexpr float real() { return 0.0; }
void real(float __val);
};

float real(const complex& __z) { return __z.real(); }

This is a bug in our implementation of the c++11 feature constexpr. We should mark constexpr member functions as being const member functions. I have entered defect DPD200236357 to fix the issue which we will do ASAP.

thanks for reporting this to us.

Judy
I have filed defect

An update to this issue. It has been fixed in the 13.0 update 2 and newer.

Jennifer

发表评论

登录添加评论。还不是成员?立即加入