Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!lll-winken!uunet!microsoft!jimad From: jimad@microsoft.UUCP (Jim ADCOCK) Newsgroups: comp.std.c++ Subject: copies and copy constructors Message-ID: <70198@microsoft.UUCP> Date: 24 Jan 91 02:20:18 GMT Reply-To: jimad@microsoft.UUCP (Jim ADCOCK) Organization: Microsoft Corp., Redmond WA Lines: 35 I'm trying to figure out where copies are "guaranteed" to exist and/or not to exist in C++, and I'm getting very confused. See Dec. JCLT for related ANSI-C issues. Part of the problem is that "copy" can be both a noun or verb thing. A "copy" can mean an invocation of a copy constructor, it can mean a separate region of memory, or it can mean both. The issue is important for "object oriented" - style programming where polymorphism and identity is important. Programmers must be able to "guarantee" in some situations that a copy is/is-not generated, so that the tests based on identity will work "correctly." In this sense, a "copy" means a distinct region of memory. Some questions: When a function returns-by-copy, is the region of memory that copy resides in distinct? [bottom of ARM page 288 seems to be implying that C++ does indeed return-by-copy, but I guess one could even question that] When, if ever, is it legal to invoke a copy constructor where the source and destination memory locations are identical? When, if ever, is it legal to invoke a copy constructor where the source and destination memory locations are partially overlapping? When, if ever, is it legal to have partially overlapping references to the same object? [please quote your sources when answering these questions] [note that most of these questions could be applied separately for compiler-initiated actions [temporaries] and for programmer initiated actions, but I'm assuming that which a compiler is allowed to do, the programmer is allowed to do, and vice-versa]