Community
cancel
Showing results for 
Search instead for 
Did you mean: 
woodbird
Beginner
91 Views

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.

0 Kudos
2 Replies
Judith_W_Intel
Employee
91 Views

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
JenniferJ
Moderator
91 Views

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

Jennifer

Reply