Created on 2002-01-23.00:00:00 last changed 171 months ago
[ Kona: In definition of operational semantics of back(), change "*tmp" to "return *tmp;" ]
[ Oxford: Matt provided new wording to address the concerns raised in Santa Cruz. It does not appear that this problem appears anywhere else in clauses 23 or 24. ]
[ Santa Cruz: the proposed resolution is even worse than what's in the current standard: erase is undefined for reverse iterator. If we're going to make the change, we need to define a temporary and use operator--. Additionally, we don't know how prevalent this is: do we need to make this change in more than one place? Martin has volunteered to review the standard and see if this problem occurs elsewhere. ]
[ There is a second possible defect; table 68 "Optional Sequence Operations" in the "Operational Semantics" column uses operations present only in the "Reversible Container" requirements, yet there is no stated dependency between these separate requirements tables. Ask in Santa Cruz if the LWG would like a new issue opened. ]
[ CuraƧao: LWG changed PR from "{ X::iterator tmp = a.end(); return *--tmp; }" to "*a.rbegin()", and from "{ X::iterator tmp = a.end(); a.erase(--tmp); }" to "a.erase(rbegin())". ]
Proposed resolution:
Change the specification in table 68 "Optional Sequence Operations" in 23.1.1/12 for "a.back()" from
*--a.end()
to
{ iterator tmp = a.end(); --tmp; return *tmp; }
and the specification for "a.pop_back()" from
a.erase(--a.end())
to
{ iterator tmp = a.end(); --tmp; a.erase(tmp); }
Table 68 "Optional Sequence Operations" in 23.1.1/12 specifies operational semantics for "a.back()" as "*--a.end()", which may be ill-formed [because calling operator-- on a temporary (the return) of a built-in type is ill-formed], provided a.end() returns a simple pointer rvalue (this is almost always the case for std::vector::end(), for example). Thus, the specification is not only incorrect, it demonstrates a dangerous construct: "--a.end()" may successfully compile and run as intended, but after changing the type of the container or the mode of compilation it may produce compile-time error.
History | |||
---|---|---|---|
Date | User | Action | Args |
2010-10-21 18:28:33 | admin | set | messages: + msg2338 |
2010-10-21 18:28:33 | admin | set | messages: + msg2337 |
2010-10-21 18:28:33 | admin | set | messages: + msg2336 |
2010-10-21 18:28:33 | admin | set | messages: + msg2335 |
2010-10-21 18:28:33 | admin | set | messages: + msg2334 |
2010-10-21 18:28:33 | admin | set | messages: + msg2333 |
2002-01-23 00:00:00 | admin | create |