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++/8910: Incorrect code generation when returning class by value


Synopsis: Incorrect code generation when returning class by value

State-Changed-From-To: open->closed
State-Changed-By: bangerth
State-Changed-When: Thu Dec 12 07:27:45 2002
State-Changed-Why:
    This is not a bug. In your conversion operator, you
    generate an unnamed object B(1234), which will then be
    assigned to the return value. However, you made the copy 
    constructor of B explicit. The standard says:
    
    An explicit constructor constructs objects just like non-explicit con-
      structors,  but  does  so  only where the direct-initialization syntax
      (_dcl.init_) or  where  casts  (_expr.static.cast_,  _expr.cast_)  are
      explicitly  used.
    
    Assigning to the return value does not happen with an
    explicit syntax, so the copy constructor cannot be used.
    
    That's it. The rest is just that gcc finds a conversion
    sequence that does what you want. Upshot: when you declare
    a class with an "explicit" copy constructor, you may not
    use it as a return value for functions that return by
    value (rather than by reference, for example).

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=8910


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