This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/34023] New: Wrong using of user-defined conversion operator for converting rvalue to reference on constant.
- From: "sergey dot gcc at comrades dot id dot au" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 8 Nov 2007 01:53:48 -0000
- Subject: [Bug c++/34023] New: Wrong using of user-defined conversion operator for converting rvalue to reference on constant.
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
// 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