ISO C++ forbids initialization in array new?

2005-08-18 Thread WU Yongwei
Well, I see this in the gcc error message.  Can someone here kindly
point to me which part of the Standard specified this behaviour?  I
thought it should be in 5.3.4, but was not able to find the words
there.

By the way, anyone knows the rationale of this behaviour?

Thanks in advance.

Best regards,

Yongwei


Re: ISO C++ forbids initialization in array new?

2005-08-22 Thread WU Yongwei
On 8/19/05, Jonathan Wakely <[EMAIL PROTECTED]> wrote:
> WU Yongwei wrote:
> > Well, I see this in the gcc error message.  Can someone here kindly
> > point to me which part of the Standard specified this behaviour?  I
> > thought it should be in 5.3.4, but was not able to find the words
> > there.
[snipped]
> This is OK, and default initialises the array, which default initialises
> each element (8.5/5)
> 
>int* i = new int[5]();
> 
> but this is not OK:
> 
>int* i = new int[5](23);
> 
> because it is not valid to initialise an array like this:
> 
>typedef int (five_ints)[5];
>five_ints i(23);
> 
> this gives:
> 
> array_init.cc:8: error: cannot initialize arrays using this syntax

This sounds reasonable.  The only problem is that it does not
constitute proof.  It is complete OK if the standard disallowed `int
a[5](23)' while allowing `new int[5](23)', just as older GCC did.

On 8/19/05, Alisdair Meredith <[EMAIL PROTECTED]> wrote:
> WU Yongwei wrote:
> 
> > Well, I see this in the gcc error message.  Can someone here kindly
> > point to me which part of the Standard specified this behaviour?  I
> > thought it should be in 5.3.4, but was not able to find the words
> > there.
> >
> > By the way, anyone knows the rationale of this behaviour?
> 
> It is not explicitly forbidden. Rather, there is no syntax defined that
> would enable it (so it is implicitly forbidden)

My observations.  According to 5.3.4, an expression like `new
int[5](23)' is well-formed.  Just that no semantics are formally
defined for it.

The behaviour might be OK, but the message seems a little misleading. 
Would something like `cannot specify initializer for arrays' be better
since it really has little to do with `array new'?

Also, the trends of gcc removing existing `extensions' are a little
worrisome.  IMHO, the extension should be allowed and a warning in the
case of `-W' or `-ansi' should be issued.

Best regards,

Yongwei