http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45923
Summary: constexpr diagnostic w/ non-literal Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassig...@gcc.gnu.org ReportedBy: b...@gcc.gnu.org This is pretty minor, but thought I'd point it out. struct complex { #if 0 constexpr complex(double r, double i) : re(r), im(i) { } #else complex(double r, double i) : re(r), im(i) { } #endif constexpr double real() { return re; } double imag() const { return im; } private: double re; double im; }; constexpr complex co1(0, 1); // literal object //constant expression data initialized by a user-defined literal constexpr double dd2 = co1.real(); // OK with: %$bin/H-x86_64-gcc-constexpr.20101004/bin/g++ --version g++ (GCC) 4.6.0 20101004 (experimental) like so: %$bin/H-x86_64-gcc-constexpr.20101004/bin/g++ -std=c++0x -c constexpr-basic.cc gives: constexpr-basic.cc:9:20: error: enclosing class of ‘constexpr double complex::real() const’ is not a literal type YES! Except the member function signature for real() has a superfulous "const" constexpr-basic.cc:17:27: error: the type ‘const complex’ of constexpr variable ‘co1’ is not literal YES! Except this is more like "invalid definition of constexpr variable 'co1' of non-literal type 'complex' constexpr-basic.cc:20:33: error: ‘double complex::real() const’ is not a constexpr function NO! Perhaps the last one should read: constexpr-basic.cc:20:33: error: member function ‘constexpr double complex::real()’ cannot be used in a constant expression with a non-literal object Or something.