From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21081 invoked by alias); 5 Apr 2004 13:50:03 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 20992 invoked by alias); 5 Apr 2004 13:49:59 -0000 Date: Mon, 05 Apr 2004 13:50:00 -0000 Message-ID: <20040405134959.20991.qmail@sources.redhat.com> From: "giovannibajo at libero dot it" To: gcc-bugs@gcc.gnu.org In-Reply-To: <20040402143013.14823.robert.schweikert@abaqus.com> References: <20040402143013.14823.robert.schweikert@abaqus.com> Reply-To: gcc-bugzilla@gcc.gnu.org Subject: [Bug c++/14823] the copy constructor is called unnecessarily/incorrectly when passing an arg by reference to the base class X-Bugzilla-Reason: CC X-SW-Source: 2004-04/txt/msg00412.txt.bz2 List-Id: ------- Additional Comments From giovannibajo at libero dot it 2004-04-05 13:49 ------- Subject: Re: the copy constructor is called unnecessarily/incorrectly when passing an arg by reference to the base class robert dot schweikert at abaqus dot com wrote: >> Where exactly does the standard speak of a rvalue-to-lvalue >> conversion? > > That would be on page 147 in the [dcl.init.ref] section (8.5.3) bullet > 5. > [...] > " > - has a class type (i.e. T2 is a class type) and can be implicitly > converted to an lvalue .... > " > > So T2 in this case would be the rvalue and the reference would be > bound to the result of the conversion (lvalue). It says: "**IF** the initializer expression [...] has a class type and can be implicitly converted to an lvalue [...] then the reference is bound directly" (my stress). So we have an if-then clause. A temporary created by the explicit function notation is a rvalue. How can it be converted to an lvalue? This is what I asked. You didn't show me where the standard says that a rvalue of that kind (or any kind) can be implicitly converted to a lvalue. There is no default conversion to do so. So the "if" condition is false. > At the end of the page one can find the following note: > " > [Note the usual lvalue-to-rvalue (4.1), array-to-pointer (4.2), and > function-to-pointer (4.3) standard conversions are not needed, and > therefore are suppressed, when such direct bindings to lvalues are > done.] Yes, but we're speaking of binding to *lvalues*. Your initializer expression is a rvalue. And there is no way it can be converted. > Lets consider the following simple example: > [...] yet this simple example compiles just fine. I don't have time to analyze it properly, but by the looks of it it shouldn't compile. If it does, it's a bug. Please, file a different bug report for this. Giovanni Bajo -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14823