Topic: Defect Report (23.1.1/12)


Author: xloe@chat.ru (Yaroslav Mironov)
Date: 25 Jan 2002 21:49:50 GMT
Raw View
Table 68 in 23.1.1/12 specifies operational semantics for "a.back()"
as "*--a.end()", which may be 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.

I suggest changing the specification for "a.back()" from

"*--a.end()"

to

"{ X::iterator tmp = a.end(); return *--tmp; }"

and the specification for "a.pop_back()" from

"a.erase(--a.end())"

to

"{ X::iterator tmp = a.end(); a.erase(--tmp); }".

Yaroslav


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]