This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Initialization with new[]


Alexander Zvyagin wrote:
> Why I can not initialize array of int[] with operator new?
it is illformed

> This is example:
>   int *b = new int[2] (1);   // initialize each element with 1
5.3.4/15
in this case we're making an array of two ints, so T is int[2].
the initializer is of the form (expressionlist), but T is not a
class type, arithmetic, enumeration, pointer, ptr to member, so
the new expression is ill-formed.

> So b[] is not initialized. Is it correct?
You code is not C++, but we should be issuing a diagnostic.
thanks for finding it.

new T[n] can only default initialize the objects within the array.

nathan

-- 
Dr Nathan Sidwell :: Computer Science Department :: Bristol University
        I have seen the death of PhotoShop -- it is called GIMP
nathan@acm.org  http://www.cs.bris.ac.uk/~nathan/  nathan@cs.bris.ac.uk


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]