This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: Initialization with new[]
- To: Alexander Zvyagin <zvyagin at gams dot ihep dot su>
- Subject: Re: Initialization with new[]
- From: Nathan Sidwell <nathan at acm dot org>
- Date: Thu, 04 Nov 1999 15:55:03 +0000
- CC: gcc-bugs at gcc dot gnu dot org
- References: <Pine.LNX.3.96.991104191942.255A-100000@gams.ihep.su>
- Reply-To: nathan at compsci dot bristol dot ac dot uk
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