This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/11328] New: userdefined implicit typecast returns wrong reference
- From: "jan at planet dot de" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 26 Jun 2003 13:33:23 -0000
- Subject: [Bug c++/11328] New: userdefined implicit typecast returns wrong reference
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11328
Summary: userdefined implicit typecast returns wrong reference
Product: gcc
Version: 3.3
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: jan at planet dot de
CC: gcc-bugs at gcc dot gnu dot org
In the appended code the implicit typecast to Base& does not return a reference to
the correct object but to a temporary instead. The typecast to Derived& works. For
gcc 2.95.3 and Borland C++ the code is ok. It is compiled with "g++ bugsim1.cc".
g++ -v:
Reading specs from /usr/lib/gcc-lib/i486-suse-linux/3.3/specs
Configured with: ../configure --enable-threads=posix --prefix=/usr
--with-local-prefix=/usr/local --infodir=/usr/share/info --mandir=/usr/share/man
--libdir=/usr/lib --enable-languages=c,c++,f77,objc,java,ada --disable-checking
--enable-libgcj --with-gxx-include-dir=/usr/include/g++ --with-slibdir=/lib
--with-system-zlib --enable-shared --enable-__cxa_atexit i486-suse-linux
Thread model: posix
gcc version 3.3 20030226 (prerelease) (SuSE Linux)
uname -a:
Linux earth 2.4.20-4GB #1 Wed Jun 18 07:45:45 UTC 2003 i686 unknown unknown
GNU/Linux
The system is a standard SuSE Linux 8.2 on Pentium 4.
*************************************
#include <iostream>
using namespace std;
class Base {
};
class Derived: public Base {
};
class Super {
public:
Derived *derived;
Super(): derived(new Derived) {}
~Super() { delete derived; }
Base *pointer() const { return derived; }
operator Base &() const { return *derived; }
operator Derived &() const { return *derived; }
};
void equalConst(const Base &base, const Derived &derived, const Base *orig)
{
cerr << "base == orig: " << (&base == orig) << " (expected 1)" << endl;
cerr << "derived == orig: " << (&derived == orig) << " (expected 1)" << endl;
}
int main()
{
Super super;
equalConst(super, super, super.pointer());
}