This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/11228] [3.3/3.4 regression] ICE on new-expression using array operator new and default-initialization
- From: "pdubuc at cas dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 6 Aug 2003 19:37:01 -0000
- Subject: [Bug c++/11228] [3.3/3.4 regression] ICE on new-expression using array operator new and default-initialization
- References: <20030617231527.11228.austern@apple.com>
- 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=11228
------- Additional Comments From pdubuc at cas dot org 2003-08-06 19:36 -------
I was interested in testing Matt Austern's Comment #6 so I wrote a little test
program. I took his comment to mean that "new int[n]()" would default
initialize all elements of the array to 0 and "new int[n]" would not. My test
seem to show that g++ doesn't work this way. Instead, I would assume that both
work like "new int[n]". Here's the program:
#include <iostream>
#define SZ 64000
int
main()
{
int n;
int* h1 = new int [SZ];
int* h2 = new int [SZ]();
for (n = 0; n < SZ; ++n)
{
if (h1[n] != h2[n] || h1[n] != 0 || h2[n] != 0)
{
std::cout << "h1[" << n << "]=" << std::hex << h1[n] << std::dec;
std::cout << ' ';
std::cout << "h2[" << n << "]=" << std::hex << h2[n] << std::dec;
std::cout << std::endl;
}
}
}
When I run this compiled with g++ 2.95.3 I get:
h1[1528]=0 h2[1528]=5f608
h1[1530]=0 h2[1530]=3
When compiled with g++ 3.3 (the bug this report documents for 3.3 doesn't happen
when 'n' is a constant instead of a variable) I get:
h1[1528]=0 h2[1528]=5fb18
h1[1530]=0 h2[1530]=3
This would seem to be the opposite of what I would expect so I commented the
parens out where h2 is allocated and I get the exact same results.
Is there a new bug here?