public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/11633] New: g++ does not initialize structures when auto-increment variables are used
@ 2003-07-22 20:53 msimons at simons-clan dot com
  2003-07-22 20:55 ` [Bug c++/11633] " msimons at simons-clan dot com
                   ` (12 more replies)
  0 siblings, 13 replies; 18+ messages in thread
From: msimons at simons-clan dot com @ 2003-07-22 20:53 UTC (permalink / raw)
  To: gcc-bugs

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.


^ permalink raw reply	[flat|nested] 18+ messages in thread
[parent not found: <bug-11633-6500@http.gcc.gnu.org/bugzilla/>]
[parent not found: <bug-11633-4@http.gcc.gnu.org/bugzilla/>]

end of thread, other threads:[~2021-11-05 23:18 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-07-22 20:53 [Bug c++/11633] New: g++ does not initialize structures when auto-increment variables are used msimons at simons-clan dot com
2003-07-22 20:55 ` [Bug c++/11633] " msimons at simons-clan dot com
2003-07-22 21:41 ` bangerth at dealii dot org
2003-07-22 21:55 ` bangerth at dealii dot org
2003-07-22 22:10 ` msimons at simons-clan dot com
2003-07-22 23:19 ` msimons at simons-clan dot com
2003-07-22 23:36 ` bangerth at dealii dot org
2003-07-23  1:09 ` msimons at simons-clan dot com
2003-07-23  9:04 ` nathan at gcc dot gnu dot org
2003-08-23 17:11 ` pinskia at gcc dot gnu dot org
2003-11-21 16:55 ` pinskia at gcc dot gnu dot org
2003-11-21 16:57 ` pinskia at gcc dot gnu dot org
2004-04-30  1:47 ` [Bug c++/11633] [DR 430] " pinskia at gcc dot gnu dot org
2004-04-30 18:17 ` pinskia at gcc dot gnu dot org
     [not found] <bug-11633-6500@http.gcc.gnu.org/bugzilla/>
2009-03-03 21:46 ` jason at gcc dot gnu dot org
2010-01-09 12:29 ` jason at gcc dot gnu dot org
     [not found] <bug-11633-4@http.gcc.gnu.org/bugzilla/>
2014-02-16 10:01 ` jackie.rosen at hushmail dot com
2021-11-05 23:18 ` timturnerc at yahoo dot com

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).