This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/33916] New: Default constructor fails to initialize array members
- From: "mec at google dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 26 Oct 2007 21:05:53 -0000
- Subject: [Bug c++/33916] New: Default constructor fails to initialize array members
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
(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