(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;
}

===

[EMAIL PROTECTED]:~/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 

[EMAIL PROTECTED]:~/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 

[EMAIL PROTECTED]:~/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

Reply via email to