// gcc version 3.4.5 (mingw-special) class a { public: template<class T> operator T &() const { static int f; return f; // line # 10 }
/* // unsafe workaround: operator a const &() const { return *this; } */ }; int main() { // : In member function `a::operator T&() const [with T = const a]': // :27: instantiated from here // :10: error: invalid initialization of reference of type 'const a&' from expression of type 'int' a const &aa = a(); // line # 27 /* // workaround: a const temp; a const &aa = temp; */ } -- Summary: Wrong using of user-defined conversion operator for converting rvalue to reference on constant. Product: gcc Version: 3.4.5 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: sergey dot gcc at comrades dot id dot au http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34023