c++/5635: no initialization for array new with initializer
Falk Hueffner
hueffner@informatik.uni-tuebingen.de
Fri Feb 8 10:31:00 GMT 2002
>Number: 5635
>Category: c++
>Synopsis: no initialization for array new with initializer
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Fri Feb 08 06:26:03 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:
>Release: 3.0
>Organization:
>Environment:
System: SunOS ogeima 5.8 Generic_108528-12 sun4u sparc SUNW,Sun-Blade-100
Architecture: sun4
host: sparc-sun-solaris2.8
build: sparc-sun-solaris2.8
target: sparc-sun-solaris2.8
configured with: ../gcc-3.0/configure --prefix=/afs/informatik.uni-tuebingen.de/sun4x_58/gcc-3.0
>Description:
g++ accepts the following construct:
int* p = new int[10](666);
which is ill-formed (according to my reading of the standard, and g++
seems to know that, since it warns when giving -ansi). However, it
does not follow the "obvoius" semantics of this statement (to
initialize all array members with the initializer, analogous to new
int[10]()), but instead doesn't initialize at all. It doesn't even
check for the type of the "initializer", new int[10](std::cout) is
also accepted
>How-To-Repeat:
hueffner@ogeima:~% cat foo.cc
#include <iostream>
int main() {
int* p = new int[10000](666);
for (int i = 0; i < 10000; ++i)
std::cout << p[i] << ' ';
std::cout << std::endl;
}
hueffner@ogeima:~% g++ foo.cc
hueffner@ogeima:~% ./a.out
0 0 0 0 0 0 0 0 0 0 0 [...] 0 0 170800 0 3 0 0 0 [...]
>Fix:
g++ should either reject this construct or give it a sensible
semantics.
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the Gcc-bugs
mailing list