This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/11633] New: g++ does not initialize structures when auto-increment variables are used
- From: "msimons at simons-clan dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 22 Jul 2003 20:53:43 -0000
- Subject: [Bug c++/11633] New: g++ does not initialize structures when auto-increment variables are used
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11633
Summary: g++ does not initialize structures when auto-increment
variables are used
Product: gcc
Version: 3.3
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: msimons at simons-clan dot com
CC: gcc-bugs at gcc dot gnu dot org
int count = 23;
int foo[] = { count++, count++, count++ };
results:
foo == { 23, 23, 23 }, count == 26;
expected:
foo == { 23, 24, 25 }, count == 26;
===
Tested only on intel platform with g++. on debian stable version 2.95.4 and a
on Redhat AS 2.1 with a self compiled version 3.3.
With g++ 2.96 from Redhat AS 2.1, if foo is a global variable (not inside any
function scope), then foo is initialized correctly to different values.
Attached to the bug is a simple test program... beta.cc
g++ -Wall -g -o beta beta.cc
gdb -q ./beta
===
(gdb) b main
Breakpoint 1 at 0x8048674: file beta.cc, line 21.
(gdb) r
Starting program: ./beta
Breakpoint 1, main () at beta.cc:21
21 static_func();
(gdb) p foo
$1 = {23, 24, 25}
(gdb) p zap
$2 = {26, 26, 26}
(gdb) s
static_func() () at beta.cc:8
8 static int bar[] = { value(), value(), value() };
(gdb) n
9 static int baz[] = { count++, count++, count++ };
(gdb) n
11 return bar[0] + baz[0];
(gdb) p bar
$3 = {29, 30, 31}
(gdb) p baz
$4 = {32, 32, 32}
===
Notice that the function calls are handled correctly, but the count++ is not.
I do not know the c++ standard, it is *possible* that the code above is
"undefined" by the standard and what g++ is doing is correct. However, the same
code compiled with at least 5 commercial compilers on various platforms all
resulted in what I say is the "expected" result with different values.