Issue 3247: fixed-length _var assignment from pointer (cxx_revision) Source: Triodia Technologies Pty Ltd (Mr. Michi Henning, michi(at)triodia.com) Nature: Uncategorized Issue Severity: Summary: the new mapping for _var types for fixed-length underlying types shows: T_var &operator=(T *t) { if (t != m_ptr) { delete m_ptr; m_ptr = t; } return *this; } This guards against self assignment when a pointer is assigned to the _var. I don't think this is right: - Assigning a pointer to a _var that already owns what the pointer points at is almost certainly an error: MyStruct * p = ...; MyStruct_var v = p; // OK // ... v = p; // Almost certainly an error - We don't do the same thing elsewhere. On page 1-13: A_var &operator=(const A_var& a) { reset(p); return *this; } This is inconsistent: assignment of a _ptr to a _var reference is not safe against self assignment, so assignment of a pointer to the _var for a fixed-length type shouldn't be either. Note that the other assignment operators are just fine -- I'm only objecting to testing for self-assignment for operator= with a pointer as the RHS. (A nice compiler could even insert an assertions if a _var is assigned the same thing that it already points at.) Resolution: Revised Text: Actions taken: January 25, 2000: received issue Discussion: deferred in June 2011 to the next RTF End of Annotations:===== Date: Tue, 25 Jan 2000 16:46:01 +1000 (EST) From: Michi Henning Reply-To: C++ Revision Task Force To: C++ Revision Task Force cc: issues@omg.org Subject: fixed-length _var assignment from pointer Message-ID: Organization: Object Oriented Concepts MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-UIDL: n]fd9?gmd9l7G!!8)Ae9 Hi, the new mapping for _var types for fixed-length underlying types shows: T_var &operator=(T *t) { if (t != m_ptr) { delete m_ptr; m_ptr = t; } return *this; } This guards against self assignment when a pointer is assigned to the _var. I don't think this is right: - Assigning a pointer to a _var that already owns what the pointer points at is almost certainly an error: MyStruct * p = ...; MyStruct_var v = p; // OK // ... v = p; // Almost certainly an error - We don't do the same thing elsewhere. On page 1-13: A_var &operator=(const A_var& a) { reset(p); return *this; } This is inconsistent: assignment of a _ptr to a _var reference is not safe against self assignment, so assignment of a pointer to the _var for a fixed-length type shouldn't be either. Note that the other assignment operators are just fine -- I'm only objecting to testing for self-assignment for operator= with a pointer as the RHS. (A nice compiler could even insert an assertions if a _var is assigned the same thing that it already points at.) Cheers, Michi. -- Michi Henning +61 7 3891 5744 Object Oriented Concepts +61 4 1118 2700 (mobile) Suite 4, 904 Stanley St +61 7 3891 5009 (fax) East Brisbane 4169 michi@ooc.com.au AUSTRALIA http://www.ooc.com.au/staff/michi-henning.html From: Paul Kyzivat To: "'C++ Revision Task Force'" Cc: issues@omg.org Subject: RE: fixed-length _var assignment from pointer Date: Tue, 25 Jan 2000 14:37:01 -0500 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2448.0) Content-Type: text/plain; charset="iso-8859-1" X-UIDL: poAe9A/p!!GU[!![D+e9 I presume you are only arguing this for the T* (adopting) constructor because you think self assignment in this case is erroneous. This makes a certain amount of sense - the caller should not be offering up this T* for adoption unless it currently owns it. But it cannot own it if the var already owns it. So, what is it that you want instead? You seem to be saying it is ok for the code to either do something unpredictable or assert. I guess that seems ok. Paul > -----Original Message----- > From: Michi Henning [mailto:michi@ooc.com.au] > Sent: Tuesday, January 25, 2000 1:46 AM > To: C++ Revision Task Force > Cc: issues@omg.org > Subject: fixed-length _var assignment from pointer > > > Hi, > > the new mapping for _var types for fixed-length underlying > types shows: > > T_var &operator=(T *t) { > if (t != m_ptr) { > delete m_ptr; > m_ptr = t; > } > return *this; > } > > This guards against self assignment when a pointer is > assigned to the _var. > > I don't think this is right: > > - Assigning a pointer to a _var that already owns what > the pointer > points at is almost certainly an error: > > MyStruct * p = ...; > MyStruct_var v = p; // OK > > // ... > > v = p; // Almost certainly an error > > - We don't do the same thing elsewhere. On page 1-13: > > A_var &operator=(const A_var& a) { > reset(p); return *this; > } > > This is inconsistent: assignment of a _ptr to a _var > reference > is not safe against self assignment, so assignment of > a pointer > to the _var for a fixed-length type shouldn't be either. > > Note that the other assignment operators are just fine -- I'm > only objecting > to testing for self-assignment for operator= with a pointer > as the RHS. > (A nice compiler could even insert an assertions if a _var is > assigned the > same thing that it already points at.) > > Cheers, > > Michi. > -- > Michi Henning +61 7 3891 5744 > Object Oriented Concepts +61 4 1118 2700 (mobile) > Suite 4, 904 Stanley St +61 7 3891 5009 (fax) > East Brisbane 4169 michi@ooc.com.au > AUSTRALIA > http://www.ooc.com.au/staff/michi-henning.html > Date: Wed, 26 Jan 2000 07:01:13 +1000 (EST) From: Michi Henning To: Paul Kyzivat cc: "'C++ Revision Task Force'" Subject: RE: fixed-length _var assignment from pointer In-Reply-To: > <9B164B713EE9D211B6DC0090273CEEA9140309@bos1.noblenet.com> Message-ID: > Organization: Object Oriented Concepts MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-UIDL: i??e9\2hd9/B!!!6$/e9 On Tue, 25 Jan 2000, Paul Kyzivat wrote: > I presume you are only arguing this for the T* (adopting) constructor > because you think self assignment in this case is erroneous. This makes a > certain amount of sense - the caller should not be offering up this T* for > adoption unless it currently owns it. But it cannot own it if the var > already owns it. > > So, what is it that you want instead? You seem to be saying it is ok for the > code to either do something unpredictable or assert. I guess that seems ok. I'm simply suggesting to not require the assignment operator to be safe in this case. The implementation should be allowed to either assert or to do something unpredictable. (I would assert, myself.) I think that's better than to mask what is almost certainly a programming error. In addition, doing this would make it consistent with the way assignment works for _var references. Cheers, Michi. -- Michi Henning +61 7 3891 5744 Object Oriented Concepts +61 4 1118 2700 (mobile) Suite 4, 904 Stanley St +61 7 3891 5009 (fax) East Brisbane 4169 michi@ooc.com.au AUSTRALIA http://www.ooc.com.au/staff/michi-henning.html From: Paul Kyzivat To: "'C++ Revision Task Force'" Subject: RE: fixed-length _var assignment from pointer Date: Tue, 25 Jan 2000 16:52:32 -0500 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2448.0) Content-Type: text/plain; charset="iso-8859-1" X-UIDL: &+Xd9JPPe9cl#"!C^K!! I presume you are only arguing this for the T* (adopting) constructor because you think self assignment in this case is erroneous. This makes a certain amount of sense - the caller should not be offering up this T* for adoption unless it currently owns it. But it cannot own it if the var already owns it. So, what is it that you want instead? You seem to be saying it is ok for the code to either do something unpredictable or assert. I guess that seems ok. Paul > -----Original Message----- > From: Michi Henning [mailto:michi@ooc.com.au] > Sent: Tuesday, January 25, 2000 1:46 AM > To: C++ Revision Task Force > Cc: issues@omg.org > Subject: fixed-length _var assignment from pointer > > > Hi, > > the new mapping for _var types for fixed-length underlying > types shows: > > T_var &operator=(T *t) { > if (t != m_ptr) { > delete m_ptr; > m_ptr = t; > } > return *this; > } > > This guards against self assignment when a pointer is > assigned to the _var. > > I don't think this is right: > > - Assigning a pointer to a _var that already owns what > the pointer > points at is almost certainly an error: > > MyStruct * p = ...; > MyStruct_var v = p; // OK > > // ... > > v = p; // Almost certainly an error > > - We don't do the same thing elsewhere. On page 1-13: > > A_var &operator=(const A_var& a) { > reset(p); return *this; > } > > This is inconsistent: assignment of a _ptr to a _var > reference > is not safe against self assignment, so assignment of > a pointer > to the _var for a fixed-length type shouldn't be either. > > Note that the other assignment operators are just fine -- I'm > only objecting > to testing for self-assignment for operator= with a pointer > as the RHS. > (A nice compiler could even insert an assertions if a _var is > assigned the > same thing that it already points at.) > > Cheers, > > Michi. > -- > Michi Henning +61 7 3891 5744 > Object Oriented Concepts +61 4 1118 2700 (mobile) > Suite 4, 904 Stanley St +61 7 3891 5009 (fax) > East Brisbane 4169 michi@ooc.com.au > AUSTRALIA > http://www.ooc.com.au/staff/michi-henning.html >