-
Key: CPP13-45
-
Legacy Issue Number: 3574
-
Status: open
-
Source: Cisco Systems ( Paul Kyzivat)
-
Summary:
The semantics for insertion of a valuetype into an Any are unclear.
(Note, this is related to issue 2531 in the IDL-to-Java RTF.
It is also related to orb_revision issue 3205.)In section 1.16.2 of ptc/2000-01-02, two forms of insertion are defined:
copying and non-copying. The non-copying form is described as:"The noncopying valuetype insertion consumes the valuetype pointed to by the
pointer that T** points to. After insertion, the caller may not access the
valuetype instance pointed to by the pointer that T* points to. The caller
maintains ownership of the storage for the pointed-to-T* itself."There is no specific description of the copying form specific to valuetypes,
so the generic description must apply:"For the copying version of operator<<=, the lifetime of the value in the
any is independent of the lifetime of the value passed to operator<<=. The
implementation of the any may not store its value as a reference or pointer
to the value passed to operator<<=."One possible interpretation (1) is that the copying form should be
implemented via a call to the _copy_value virtual function, while the
non-copying form should simply retain the provided pointer (without calling
_add_ref) and eventually call _remove_ref when done with it.If so, what is the significance of the rule about the caller not continuing
to use the pointer? It it only that it has lost a reference count, and may
continue using the pointer if it has another reference count? Or does this
imply that continued access to the value is forbidden regardless of
reference count?Another possible interpretation (2) is that the description is nonsense, and
that the non-copying form should use _add_ref and the copying form should
use _copy_value. In this interpretation the caller would be free to continue
using the original pointer and would be obligated to _remove_ref it
eventually. This seems like a more practical interpretation, but is
inconsistent with usage for other non-copying insertions.Suggested Resolution:
Replace the paragraph on non-copying insertion of valuetypes (quoted above)
with:"The noncopying valuetype insertion takes ownership of one reference count
to the valuetype pointed to by the pointer that T** points to. After
insertion, the caller should treat the pointer as if _remove_ref had been
called on it. The caller maintains ownership of the storage for the
pointed-to-T* itself.""For copying valuetype insertion, the lifetime of the value in the any is
independent of the lifetime of the value provided. The implementation of the
any shall duplicate the value using the virtual function _copy_value or an
equivalent mechanism. The caller retains ownership of the T* pointer and
remains obliged to call _remove_ref on it." -
Reported: CPP 1.1 — Thu, 20 Apr 2000 04:00 GMT
-
Updated: Fri, 6 Mar 2015 20:57 GMT
CPP13 — unclear semantics for valuetype insertion into Any
- Key: CPP13-45
- OMG Task Force: C++ June 2011 RTF