This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: a further question


Looking at this code, it seems the libstdc++ behaviour is acceptable: when using `putback(c)`
with a character which doesn't match the character in the putback location it can succeed:

- According to 27.6.3.2.4 [streambuf.pub.pback] paragraph 1:
    Returns: If the input sequence putback position is not available, or if traits::eq(c,gptr()[-1]) is
        false, returns pbackfail(traits::to_int_type(c)). ...
  This condition is clearly true: there there is no putback position after having seeked to some
  location in the stream or the position hold a different character ('c' instead of 'a'). In either case
  `std::basic_filebuf<...>::pbackfail(c)` is called.
- According t 27.9.1.5 [filebuf.virtuals] paragraph 5 second bullet:
    If traits::eq_int_type(c,traits::eof()) returns false and if the function makes a putback
    position available and if the function is permitted to assign to the putback position, decrements
    the next pointer for the input sequence, and stores c there.
  Now the question becomes: 	is the function permitted to assign to the putback position?

I didn't see any definition under which pbackfail() is not allowed to write to the putback position.
There is a weasel wording clause about the same behaviour as C streams in 27.9.1.1 paragraph 2
but the C standard is actually more explicit about pushing back characters, allowing arbitrary
characters to be pushed back. That would actually indicate that the libstdc++ behaviour is correct
while the libc++ behaviour (it fails upon the first putback()) could be wrong. I'd be inclined to read
the standard to allow both behaviours.

The words as they stand right now are not entirely clear and I'd think it would be a valid issue
against the standard. Since there aren't any real guarantees about putback characters and I
never found them particularly useful, I'm not going to report it. Instead, my recommendation with
respect to IOStream putback is: don't do it. It isn't necessary anyway.

Thanks,
  Dietmar

On 27 Nov 2013, at 19:39, Jonathan Wakely <jwakely.gcc@gmail.com> wrote:

On 27 November 2013 14:15, Dietmar Kuehl wrote:
> 
> Hi Graziano,
> 
> I didn't see your question before (did you mail me directly or ask on Stackoverflow)?

It was http://gcc.gnu.org/ml/libstdc++/2013-11/msg00127.html (and the
same question was asked on the gcc-help list, but I suggested sending
it here, as I'm the only libstdc++ expert on the gcc-help list and I
haven't had time to analyze the question - thanks for looking at it,
Dietmar!)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]