Title
accessing containers from their elements' special functions
Status
nad
Section
[containers]
Submitter
Martin Sebor

Created on 2004-06-28.00:00:00 last changed 164 months ago

Messages

Date: 2010-10-21.18:28:33

Rationale:

Recommend NAD. We agree this is an issue, but not a defect. We believe that there is no wording we can put in the standard that will cover all cases without introducing unfortunate corner cases.

Date: 2010-10-21.18:28:33

[ Redmond: This is a real issue, but it's probably a clause 17 issue, not clause 23. We get the same issue, for example, if we try to destroy a stream from one of the stream's callback functions. ]

Date: 2010-10-21.18:28:33

Proposed resolution:

Add to Container Requirements the following new paragraph:

    Unless otherwise specified, the behavior of a program that
    invokes a container member function f from a member function
    g of the container's value_type on a container object c that
    called g from its mutating member function h, is undefined.
    I.e., if v is an element of c, directly or indirectly calling
    c.h() from v.g() called from c.f(), is undefined.
Date: 2004-06-28.00:00:00

The standard doesn't prohibit the destructors (or any other special functions) of containers' elements invoked from a member function of the container from "recursively" calling the same (or any other) member function on the same container object, potentially while the container is in an intermediate state, or even changing the state of the container object while it is being modified. This may result in some surprising (i.e., undefined) behavior.

Read email thread starting with c++std-lib-13637 for more.

History
Date User Action Args
2010-10-21 18:28:33adminsetmessages: + msg2757
2010-10-21 18:28:33adminsetmessages: + msg2756
2010-10-21 18:28:33adminsetmessages: + msg2755
2004-06-28 00:00:00admincreate