This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: c++/9807: Derived class object used as default parameter for base class reference requires explicit cast to reference to base class


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]