public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/14417] New: output streams and post-increment operator have incorrect output.
@ 2004-03-03 20:59 mcvick_e at iname dot com
2004-03-03 21:15 ` [Bug c++/14417] " bangerth at dealii dot org
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: mcvick_e at iname dot com @ 2004-03-03 20:59 UTC (permalink / raw)
To: gcc-bugs
Utilizing the post increment operator within a stream operation does not result
in the expected output. Output is reversed. Based on the grammer of the
language, this should work as expected and not as currently implemented.
THe following program will replicate the problem:
#include <iostream>
#include <fstream>
using namespace std;
char *str = "0123456789ABCDEF";
int main(int argc, char **argv)
{
char *ptr;
#if defined(COUT_TOO)
ptr = str;
cout << *ptr++ << *ptr++ << ' ';
cout << *ptr++ << *ptr++ << ' ';
cout << *ptr++ << *ptr++ << ' ';
cout << *ptr++ << *ptr++ << ' ';
cout << *ptr++ << *ptr++ << ' ';
cout << *ptr++ << *ptr++ << ' ';
cout << *ptr++ << *ptr++ << ' ';
cout << *ptr++ << *ptr++ << ' ';
cout << endl;
#endif
ostream *outStream;
outStream = new ofstream("foo.txt");
ptr = str;
*outStream << *ptr++ << *ptr++ << ' ';
*outStream << *ptr++ << *ptr++ << ' ';
*outStream << *ptr++ << *ptr++ << ' ';
*outStream << *ptr++ << *ptr++ << ' ';
*outStream << *ptr++ << *ptr++ << ' ';
*outStream << *ptr++ << *ptr++ << ' ';
*outStream << *ptr++ << *ptr++ << ' ';
*outStream << *ptr++ << *ptr++ << ' ';
*outStream << endl;
delete outStream;
// Same concept, different syntax works.
#if defined(COUT_TOO)
ptr = str;
cout << *ptr++;
cout << *ptr++ << ' ';
cout << *ptr++;
cout << *ptr++ << ' ';
cout << *ptr++;
cout << *ptr++ << ' ';
cout << *ptr++;
cout << *ptr++ << ' ';
cout << *ptr++;
cout << *ptr++ << ' ';
cout << *ptr++;
cout << *ptr++ << ' ';
cout << *ptr++;
cout << *ptr++ << ' ';
cout << *ptr++;
cout << *ptr++ << ' ';
cout << endl;
#endif
outStream = new ofstream("bar.txt");
ptr = str;
*outStream << *ptr++;
*outStream << *ptr++ << ' ';
*outStream << *ptr++;
*outStream << *ptr++ << ' ';
*outStream << *ptr++;
*outStream << *ptr++ << ' ';
*outStream << *ptr++;
*outStream << *ptr++ << ' ';
*outStream << *ptr++;
*outStream << *ptr++ << ' ';
*outStream << *ptr++;
*outStream << *ptr++ << ' ';
*outStream << *ptr++;
*outStream << *ptr++ << ' ';
*outStream << *ptr++;
*outStream << *ptr++ << ' ';
*outStream << endl;
}
The above program was compiled with the following command:
g++ -O0 -o foobar test.cxx -DCOUT_TOO
The output on the screen and found in the files is thus:
10 32 54 76 98 BA DC FE
01 23 45 67 89 AB CD EF
The specs of the compiler obtained with g++ -v is:
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.3.3/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--disable-checking --disable-libunwind-exceptions --with-system-zlib
--enable-__cxa_atexit --host=i386-redhat-linux
Thread model: posix
gcc version 3.3.3 20040216 (Red Hat Linux 3.3.3-2)
I have even tried the latest snapshot of GCC 3.3.3 and it fails as well. I also
compiled 3.3.1 and used it with the same results.
--
Summary: output streams and post-increment operator have
incorrect output.
Product: gcc
Version: 3.3.3
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: mcvick_e at iname dot com
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: i386-redhat-linux
GCC host triplet: i386-redhat-linux
GCC target triplet: i386-redhat-linux
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14417
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/14417] output streams and post-increment operator have incorrect output.
2004-03-03 20:59 [Bug c++/14417] New: output streams and post-increment operator have incorrect output mcvick_e at iname dot com
@ 2004-03-03 21:15 ` bangerth at dealii dot org
2004-03-03 23:09 ` mcvick_e at iname dot com
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: bangerth at dealii dot org @ 2004-03-03 21:15 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From bangerth at dealii dot org 2004-03-03 21:15 -------
No bug, please read the page on frequently reported bugs. operator<<
is not a sequence point, so the question of when the pointer is
increased and when it is dereferenced is undefined.
W.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14417
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/14417] output streams and post-increment operator have incorrect output.
2004-03-03 20:59 [Bug c++/14417] New: output streams and post-increment operator have incorrect output mcvick_e at iname dot com
2004-03-03 21:15 ` [Bug c++/14417] " bangerth at dealii dot org
@ 2004-03-03 23:09 ` mcvick_e at iname dot com
2004-03-03 23:23 ` bangerth at dealii dot org
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: mcvick_e at iname dot com @ 2004-03-03 23:09 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From mcvick_e at iname dot com 2004-03-03 23:09 -------
(In reply to comment #1)
> No bug, please read the page on frequently reported bugs. operator<<
> is not a sequence point, so the question of when the pointer is
> increased and when it is dereferenced is undefined.
>
> W.
It's interesting that this has worked historically. I see g++ 2.9.5 work
appropriately on our Sun Solaris stations, as well as V3 work appropriately on
our Macintosh systems.
I guess we'll resort to using something that actually works as most people
would expect it to.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14417
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/14417] output streams and post-increment operator have incorrect output.
2004-03-03 20:59 [Bug c++/14417] New: output streams and post-increment operator have incorrect output mcvick_e at iname dot com
2004-03-03 21:15 ` [Bug c++/14417] " bangerth at dealii dot org
2004-03-03 23:09 ` mcvick_e at iname dot com
@ 2004-03-03 23:23 ` bangerth at dealii dot org
2004-08-05 14:57 ` bangerth at dealii dot org
2004-08-05 15:01 ` bangerth at dealii dot org
4 siblings, 0 replies; 6+ messages in thread
From: bangerth at dealii dot org @ 2004-03-03 23:23 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From bangerth at dealii dot org 2004-03-03 23:23 -------
The standard says that the behavior of your program is undefined in this
case. Newer compilers are better at optimizing code, so they trip users
writing undefined code more often. It's not the compiler's fault if it
reorders code that the standard allows it to reorder.
W.
PS: To understand what's going on, read the entry on -Wsequence-point
in the manual.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14417
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/14417] output streams and post-increment operator have incorrect output.
2004-03-03 20:59 [Bug c++/14417] New: output streams and post-increment operator have incorrect output mcvick_e at iname dot com
` (2 preceding siblings ...)
2004-03-03 23:23 ` bangerth at dealii dot org
@ 2004-08-05 14:57 ` bangerth at dealii dot org
2004-08-05 15:01 ` bangerth at dealii dot org
4 siblings, 0 replies; 6+ messages in thread
From: bangerth at dealii dot org @ 2004-08-05 14:57 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From bangerth at dealii dot org 2004-08-05 14:57 -------
Reopen these bugs...
--
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |UNCONFIRMED
Resolution|INVALID |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14417
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/14417] output streams and post-increment operator have incorrect output.
2004-03-03 20:59 [Bug c++/14417] New: output streams and post-increment operator have incorrect output mcvick_e at iname dot com
` (3 preceding siblings ...)
2004-08-05 14:57 ` bangerth at dealii dot org
@ 2004-08-05 15:01 ` bangerth at dealii dot org
4 siblings, 0 replies; 6+ messages in thread
From: bangerth at dealii dot org @ 2004-08-05 15:01 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From bangerth at dealii dot org 2004-08-05 15:01 -------
...mark as duplicate of PR 11751.
*** This bug has been marked as a duplicate of 11751 ***
--
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |DUPLICATE
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14417
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2004-08-05 15:01 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-03-03 20:59 [Bug c++/14417] New: output streams and post-increment operator have incorrect output mcvick_e at iname dot com
2004-03-03 21:15 ` [Bug c++/14417] " bangerth at dealii dot org
2004-03-03 23:09 ` mcvick_e at iname dot com
2004-03-03 23:23 ` bangerth at dealii dot org
2004-08-05 14:57 ` bangerth at dealii dot org
2004-08-05 15:01 ` bangerth at dealii dot org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).