This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: c++/9807: Derived class object used as default parameter for base class reference requires explicit cast to reference to base class
- From: bangerth at dealii dot org
- To: frank6thursday at aol dot com, gcc-bugs at gcc dot gnu dot org, gcc-prs at gcc dot gnu dot org, nobody at gcc dot gnu dot org
- Date: 5 Mar 2003 22:06:50 -0000
- Subject: Re: c++/9807: Derived class object used as default parameter for base class reference requires explicit cast to reference to base class
- Reply-to: bangerth at dealii dot org, frank6thursday at aol dot com, gcc-bugs at gcc dot gnu dot org, gcc-prs at gcc dot gnu dot org, nobody at gcc dot gnu dot org, gcc-gnats at gcc dot gnu dot org
Synopsis: Derived class object used as default parameter for base class reference requires explicit cast to reference to base class
State-Changed-From-To: open->analyzed
State-Changed-By: bangerth
State-Changed-When: Wed Mar 5 22:06:50 2003
State-Changed-Why:
Confirmed. I think the compiler should accept this, but
no version of gcc does that. It works, though, if the
reference parameter is constant.
Here's a smaller code:
----------------------
struct A {
virtual ~A();
};
struct B : A {};
struct C {
C(A& a = B()){}
};
C c;
------------------------
This is what I get:
g/x> /home/bangerth/bin/gcc-3.4-pre/bin/c++ -c x.cc
x.cc:9: error: could not convert `B()' to `A&'
x.cc:7: error: in passing argument 1 of `C::C(A&)'
There's something more weird: If I remove the virtual
destructor, then I get the following error message:
g/x> /home/bangerth/bin/gcc-3.4-pre/bin/c++ -c x.cc
x.cc:9: error: could not convert `{}' to `A&'
^^^^
!!!!
x.cc:7: error: in passing argument 1 of `C::C(A&)'
That looks like real bogus!
W.
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=9807