Re: Defect Report: istreambuf_iterator should have an operator->()
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. 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 - and, in fact, it
is:
"The use of a pseudo-destructor-name after a dot . or arrow ->
operator represents the destructor for the non-class type named by
type-name. The result shall only be used as the operand for the
function call operator (), and the result of such a call has type
void. The only effect is the evaluation of the postfix-expression
before the dot or arrow." [?5.2.4/2]
Greg
---
[ 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 ]