I just tried to build a rather large chunk of code using clang 3.3 with the header files of the GCC 4.7.3 standard library on Ubuntu 13.04. Everything went well, except for one question. This code already compiles with the standard Ubuntu clang 3.2 package on this computer, so I assume these are some changes to the clang 3.3 compiler. The problem is with const and constexpr using a complex header. In particular, a complex type has the following code block
#ifdef __GXX_EXPERIMENTAL_CXX0X__ // _GLIBCXX_RESOLVE_LIB_DEFECTS // DR 387. std::complex over-encapsulated. constexpr double real() { return __real__ _M_value; } constexpr double imag() { return __imag__ _M_value; }
In my compilation, I enter the first block of code and so the compiler sees
constexpr double real() { return __real__ _M_value; }
This causes clang to create an error that the actual member function is not const with the following
/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../include/c++/4.7/complex:1212:7: note: candidate function not viable: 'this' argument has type 'const complex<double>', but method is not marked const real() { return __real__ _M_value; }
I read the following post The difference between `constexpr` and` const` and several other similar documents, but I still do not quite understand if this is a GCC header problem or a clan compiler problem. I feel that the member function designated by constexpr should be considered by the compiler as const, in which case clang is wrong.
source share