Re: Defect Report: istreambuf_iterator should have an operator->()
On Mar 26, 7:52 pm, "Greg Herlihy" <gre...@pacbell.net> wrote:
On Mar 26, 7:40 am, "James Kanze" <james.ka...@gmail.com> wrote:
On Mar 26, 1:40 am, nore...@this.is.invalid (Niels Dekker - no return
address) wrote:
Based on Greg's example, the following code demonstrates the issue:
#include <iostream>
#include <fstream>
#include <streambuf>
typedef char C;
int main ()
{
std::ifstream s("filename", std::ios::in);
std::istreambuf_iterator<char> i(s);
(*i).~C(); // This is well-formed...
Well formed, perhaps, but it looks like undefined behavior at
execution. (Maybe not in the case of char; char's rather
special in this regard. But definitily in the case of other
types.)
There would no point in allowing pseudo-destructor calls in C++ unless
such calls had well-defined behavior.
The call itself may have well-defined behavior, but you can't
use it just anywhere. In the case of a streambuf_iterator, the
streambuf_iterator is managing the life of the object itself,
and any destruction of the object from outside the
streambuf_iterator will fatally cause problems with that
management.
Otherwise, the Standard would
simply be trading a compilation error for undefined behavior - which
would not be a sensible trade. So we can be assured that a psuedo-
destructor call for any scalar type is well-defined
No one is doubting that. The problem is that what remains isn't
an object. And that if what remains remains somewhere where
someone can use it, and probable destruct it themselves, the
results will be undefined behavior. You wouldn't expect to be
allowed to do iter->~Toto() on an iterator from
std::vector<Toto>, would you? What makes streambuf_iterator
different?
--
James Kanze (GABI Software) mailto:james.kanze@gmail.com
Conseils en informatique orient?e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S?mard, 78210 St.-Cyr-l'?cole, France, +33 (0)1 30 23 00 34
---
[ 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.comeaucomputing.com/csc/faq.html ]