public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/33916]  New: Default constructor fails to initialize array members
@ 2007-10-26 21:06 mec at google dot com
  2007-10-31 20:08 ` [Bug c++/33916] " crowl at google dot com
                   ` (14 more replies)
  0 siblings, 15 replies; 16+ messages in thread
From: mec at google dot com @ 2007-10-26 21:06 UTC (permalink / raw)
  To: gcc-bugs

(This may be related to PR 30111 )

In this program, a default constructor fails to initialize the given array
members to zero.  Results are shown with several versions of gcc.

===

#include <string.h>
#include <iostream>

namespace {

class Stats {
  friend void alpha();
  private:
    int a_[12];
    int b_[12];
};

void dirty_stack() {
  char array[4096];
  memset(array, 0x11, 4096);
}

void alpha() {
  Stats my_stats = Stats();
  for (int i = 0; i < 12; ++i) {
    std::cout << my_stats.a_[i] << " ";
  }
  std::cout << std::endl;
}

}

int main() {
  dirty_stack();
  alpha();
  return 0;
}

===

mec@hollerith:~/exp-array-default$ /home/mec/gcc-4.1.2/install/bin/g++ z3.cc &&
./a.out
0 0 0 0 0 0 0 0 0 0 0 0 

mec@hollerith:~/exp-array-default$ /home/mec/gcc-4.2.2/install/bin/g++ z3.cc &&
./a.out
286331153 286331153 286331153 286331153 286331153 286331153 286331153 286331153
286331153 286331153 286331153 286331153 

mec@hollerith:~/exp-array-default$ /home/mec/gcc-4.3-20071019/install/bin/g++
z3.cc && ./a.out
286331153 286331153 286331153 286331153 286331153 286331153 286331153 286331153
286331153 286331153 286331153 286331153


-- 
           Summary: Default constructor fails to initialize array members
           Product: gcc
           Version: 4.2.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: mec at google dot com
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33916


^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2008-02-12  6:42 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-10-26 21:06 [Bug c++/33916] New: Default constructor fails to initialize array members mec at google dot com
2007-10-31 20:08 ` [Bug c++/33916] " crowl at google dot com
2007-11-01  2:17 ` gdr at gcc dot gnu dot org
2007-12-11  0:04 ` [Bug c++/33916] [4.2/4.3 Regression] " janis at gcc dot gnu dot org
2007-12-11  0:17 ` pinskia at gcc dot gnu dot org
2007-12-12 20:55 ` mmitchel at gcc dot gnu dot org
2008-01-02 23:49 ` mmitchel at gcc dot gnu dot org
2008-01-07 19:21 ` mmitchel at gcc dot gnu dot org
2008-01-07 19:47 ` crowl at google dot com
2008-01-22 21:23 ` steven at gcc dot gnu dot org
2008-01-25 16:54 ` rguenth at gcc dot gnu dot org
2008-02-01 17:01 ` jsm28 at gcc dot gnu dot org
2008-02-04  3:30 ` jason at gcc dot gnu dot org
2008-02-04 12:15 ` [Bug c++/33916] [4.2 " rguenth at gcc dot gnu dot org
2008-02-12  6:39 ` jason at gcc dot gnu dot org
2008-02-12  6:42 ` jason at gcc dot gnu 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).