This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/20427] New: 'new int [2] ()' not default initialized
- From: "andrew dot stubbs at st dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 11 Mar 2005 16:33:23 -0000
- Subject: [Bug c++/20427] New: 'new int [2] ()' not default initialized
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
According to my reading of ISO 14882 section 5.3.4 paragraph 15, arrays
initialized with 'new' and a trailing '()' should be 'default-initialized'.
According to section 8.5 paragraph 5, the definition of 'default-initialized'
for an array is that each entry in the array should be 'zero-initialized'.
This used to be the case in 3.2.2, but is not the case in 3.4.3.
The following program demonstrates the problem:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int
main()
{
// dirty heap so that initialized data shows up
char *string = (char *)malloc(sizeof"hello");
strcpy (string, "hello");
printf ("here: %s\n", string);
free (string);
// i[0] and i[1] should both be zero when the following
// line contains () and something else whn it does not.
int *i = new int [2] ();
printf ("%p, %d, %d\n", i, i[0], i[1]);
return 0;
}
--
Summary: 'new int [2] ()' not default initialized
Product: gcc
Version: 3.4.3
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: andrew dot stubbs at st dot com
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20427