Title
Member function reentrancy should be implementation-defined
Status
open
Section
[reentrancy]
Submitter
Stephan T. Lavavej

Created on 2014-07-01.00:00:00 last changed 1 month ago

Messages

Date: 2021-07-30.02:16:19

Proposed resolution:

This wording is relative to N4892.

  1. Add the following paragraph to [reentrancy]:

    -?- During the execution of a standard library non-static member function F on an object, if that object is accessed through a glvalue that is not obtained, directly or indirectly, from the this pointer of F, in a manner that can conflict ([intro.races]) with any access that F is permitted to perform ([res.on.data.races]), the behavior is undefined unless otherwise specified.

Date: 2021-07-29.00:00:00

[ 2021-07-29 Tim suggests new wording ]

The "this pointer" restriction is modeled on [class.cdtor] p2. It allows us to continue to specify a member function f as calling some other member function g, since any such call would use something obtained from the first member function's this pointer.

In all other cases, this wording disallows such "recursion on object" unless both member functions are const (or are treated as such for the purposes of data race avoidance). Using "access" means that we also cover direct access to the object representation, such as the following pathological example from Arthur O'Dwyer, which is now undefined:

std::string s = "hello world";
char *first = (char*)&s;
char *last = (char*)(&s + 1);
s.append(first, last);
Date: 2021-07-30.02:16:19

[ 2016-05 email from STL ]

I don't have any better suggestions than my original PR at the moment.

Previous resolution [SUPERSEDED]:

This wording is relative to N3936.

  1. Change [reentrancy] p1 as indicated:

    -1- Except where explicitly specified in this standard, it is implementation-defined which functions (including different member functions called on a single object) in the Standard C++ library may be recursively reentered.

Date: 2017-02-02.00:41:18

[ 2015-07 Telecon Urbana ]

Marshall to ping STL for updated wording.

Date: 2014-11-03.00:00:00

[ 2014-11-03 Urbana ]

AJM confirmed with SG1 that they had no special concerns with this issue, and LWG should retain ownership.

AM: this is too overly broad as it also covers calling the exact same member function on a different object
STL: so you insert into a map, and copying the value triggers another insertion into a different map of the same type
GR: reentrancy seems to imply the single-threaded case, but needs to consider the multi-threaded case

Needs more wording.

Move to Open

Date: 2014-07-01.00:00:00

N3936 [reentrancy]/1 talks about "functions", but that doesn't address the scenario of calling different member functions of a single object. Member functions often have to violate and then re-establish invariants. For example, vectors often have "holes" during insertion, and element constructors/destructors/etc. shouldn't be allowed to observe the vector while it's in this invariant-violating state. The [reentrancy] Standardese should be extended to cover member functions, so that implementers can either say that member function reentrancy is universally prohibited, or selectively allowed for very specific scenarios.

(For clarity, this issue has been split off from LWG 2382.)

History
Date User Action Args
2021-07-30 02:16:19adminsetmessages: + msg11978
2017-11-05 05:11:26adminsetmessages: + msg9505
2015-09-27 20:55:06adminsetmessages: + msg7553
2014-11-08 18:05:15adminsetstatus: new -> open
2014-11-08 18:01:47adminsetstatus: open -> new
2014-11-08 16:43:57adminsetmessages: + msg7176
2014-11-08 16:43:57adminsetstatus: new -> open
2014-07-02 20:30:26adminsetmessages: + msg7090
2014-07-01 00:00:00admincreate