Analysis of libstdc++/2071 test case
Loren James Rittle
rittle@latour.rsch.comm.mot.com
Tue May 8 23:56:00 GMT 2001
Thanks to Benjamin for telling me where I might look, I now understand
the failure mode of this test case (simplified from libstdc++/1620
and/or slightly extended from libstdc++/2071):
#include <iostream>
using namespace std;
int main()
{
int i;
cin >> i;
cout << "i == " << i << endl;
}
and why it is not being seen on all platforms.
By repeatedly single-stepping through the code when stdin is hooked to
interactive and non-interactive streams, I have discovered a much
simpler test case (with about as much return value checking as the
libstdc++ code ;-) that reveals a known portability issue (and indeed
mirrors the exact sequence of relevant IO calls made by libstdc++ code
in the above test case).
#include <errno.h>
#include <stdio.h>
int main ()
{
char buf;
char buf2;
int error = 0;
fread (&buf, 1, 1, stdin);
fseek (stdin, 0, SEEK_CUR);
fread (&buf2, 1, 1, stdin);
printf ("%d %d %d\n", buf, buf2, error);
}
When run on Red Hat Linux 6.1 (Cartman) (with whatever glibc was the default):
; a.out
1234<CR>
1 2
When run on Solaris 5.7 (with Sun libc):
; a.out
1234<CR>
<CR>
1
When run on FreeBSD 4.2 (with BSD libc):
; a.out
1234<CR>
<CR>
1
When run on Digital UNIX V4.0A (with OSF1 libc):
; a.out
1234<CR>
1 2
When run on Red Hat Linux 6.1 (Cartman), FreeBSD 4.2, Digital UNIX V4.0A:
; echo 1234 | a.out
1 2
When run on Solaris 5.7 (with Sun libc):
; echo 1234|a.out
1 (unprintable character)
All mentioned platforms:
; cat >B
1234<CR><EOF>
; a.out <B
1 2
My reading of ISO-C-1999 was of no help in resolving which set of
implementations are wrong, if any. Not that it would matter since
Solaris is considered a primary platform and failure when cin is an
interactive stream breaks almost all non-trivial C++ programs.
No patch yet.
Regards,
Loren
More information about the Libstdc++
mailing list