Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!uwm.edu!rpi!zaphod.mps.ohio-state.edu!think!snorkelwacker!apple!portal!cup.portal.com!pkturner From: pkturner@cup.portal.com (Prescott K Turner) Newsgroups: comp.lang.c++ Subject: Re: Use of temporaries in assignments Message-ID: <30152@cup.portal.com> Date: 23 May 90 04:41:01 GMT References: <2654126F.17958@paris.ics.uci.edu> Organization: The Portal System (TM) Lines: 32 rfg@paris.ics.uci.edu (Ronald Guilmette) writes: > // I have just started to look at the code generated for simple statements of > // the general form: base = derived; > // > // It seems that the legality of such statements relies on the use of > // base::operator=(const base&) operators (which are implicitly generated > // by the compiler when not explicitly declared) and upon automatic implicit > // (multi-stage?) conversions of values of type `derived' to values of type > // `base&'. More precisely, an lvalue of type derived is converted directly to a reference to base. > // It seems to me that uses of these (sometimes implicitly generated) assignm ent > // operators should mean that statements of the general form shown above shou > // never involve the creation of temporaries or calls to constructors or > // destructors. The rule for initializing references changed as of cfront 2.0. It applies to parameters such as the "const base &" in the implicitly-generated assignment operator for base. For certain types of actual arguments, a temporary is created (implying calls to constructors and destructors). > base_object = derived_object; In this assignment statement, the derived object is not const. I don't think the annotated reference manual is clear on this, but it seems sufficient grounds for cfront to create a temporary. -- Prescott K. Turner, Jr. Language Processors, Inc. 959 Concord St., Framingham, MA 01701 USA (508) 626-0006 x232 UUCP: ...sun!cup.portal.com!pkturner Internet: pkturner@cup.portal.com