From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27666 invoked by alias); 12 Dec 2002 15:27:46 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 27647 invoked by uid 61); 12 Dec 2002 15:27:45 -0000 Date: Thu, 12 Dec 2002 07:27:00 -0000 Message-ID: <20021212152745.27646.qmail@sources.redhat.com> To: gcc-bugs@gcc.gnu.org, gcc-prs@gcc.gnu.org, lgandhi@peerless.com, nobody@gcc.gnu.org From: bangerth@dealii.org Reply-To: bangerth@dealii.org, gcc-bugs@gcc.gnu.org, gcc-prs@gcc.gnu.org, lgandhi@peerless.com, nobody@gcc.gnu.org, gcc-gnats@gcc.gnu.org Subject: Re: c++/8910: Incorrect code generation when returning class by value X-SW-Source: 2002-12/txt/msg00708.txt.bz2 List-Id: 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