From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7918 invoked by alias); 2 Apr 2004 18:22:26 -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 7911 invoked by alias); 2 Apr 2004 18:22:25 -0000 Date: Fri, 02 Apr 2004 18:22:00 -0000 Message-ID: <20040402182225.7909.qmail@sources.redhat.com> From: "robert dot schweikert at abaqus dot com" 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/msg00204.txt.bz2 List-Id: ------- Additional Comments From robert dot schweikert at abaqus dot com 2004-04-02 18:22 ------- Subject: Re: the copy constructor is called unnecessarily/incorrectly when passing an arg by reference to the base class On Fri, 2004-04-02 at 13:01, pinskia at gcc dot gnu dot org wrote: > ------- Additional Comments From pinskia at gcc dot gnu dot org 2004-04-02 18:01 ------- > No it is not complaining on that, it is complaining on: > typedef void* omu_Ptr; > typedef omu_Varray omu_VarrayPtr; > .... > : rgnF_GeomSet (fl, vrec, erec, frec, crec, omu_VarrayPtr(), <--- rvalue (omu_VarrayPtr () ), so you need > to access the copy > constror Nope, I disagree. I did look at the sections in the standard that the changes page refers to and found the following: " A reference to type "cv1 T1" is initialized by an expression of type "cv2 T2" as follows: - If the initializer expression - is an lvalue ..... (clearly not the case here) - has a class type (i.e. T2 is a class type) and can be implicitly converted to an lvalue of type "cv3 T3" where "cv1 T1" is reference-compatible with "cv3 T3" (this conversion is selected by enumerating the applicable conversion functions and choosing the best one through overload resolution) then the reference is bound directly to the initializer expression lvalue in the first case, and the reference is bound to the lvalue result of the conversion the second case. In these cases the reference is said to bind directly to the initializer expression....... " The text can be found in the first sub bullet of bullet 5 in section 8.5.3 and IMHO this is the case that applies here as the rvalue of omu_VarrayPtr() can be converted to an lvalue (no copy constructor needed) and the reference can then be bound directly to the lvalue that results from the conversion. Whether or not the copy ctor is private makes no difference in this case. I will try and come up with a simpler example. Thanks, Robert > name, how_to_split, > how_to_merge), > > .... (before, the base class class constructor): > rgnF_GeomSet ( > ftr_FeatureList*, > const omu_VarrayPtr& vrec, > const omu_VarrayPtr& erec, > const omu_VarrayPtr& frec, > const omu_VarrayPtr& crec, > const omu_VarrayPtr& rrec, > const cow_String& name, > cax_MigrationType how_to_split = cax_SPLIT_COPY, > cax_MigrationType how_to_merge = cax_MERGE_EXPAND); -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14823