-
Key: CPP13-29
-
Legacy Issue Number: 3247
-
Status: open
-
Source: Triodia Technologies Pty Ltd ( Michi Henning)
-
Summary:
the new mapping for _var types for fixed-length underlying types shows:
T_var &operator=(T *t) {
{ delete m_ptr; m_ptr = t; }
if (t != m_ptr)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.) - Assigning a pointer to a _var that already owns what the pointer
-
Reported: CPP 1.1 — Tue, 25 Jan 2000 05:00 GMT
-
Updated: Fri, 6 Mar 2015 20:57 GMT