public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* C++: variable length arrays and operator new[]
@ 2009-09-20  9:59 Florian Weimer
  2009-09-21 21:56 ` Ian Lance Taylor
  0 siblings, 1 reply; 4+ messages in thread
From: Florian Weimer @ 2009-09-20  9:59 UTC (permalink / raw)
  To: gcc

G++ currently accepts the following code:

char *
alloc(unsigned a, unsigned b)
{
  typedef char array[a];
  return &**(new array[b]);
}

Is this intentional?  The equivalent "new char[a][b]" is rejected (as
required by the C++ standard).

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: C++: variable length arrays and operator new[]
  2009-09-20  9:59 C++: variable length arrays and operator new[] Florian Weimer
@ 2009-09-21 21:56 ` Ian Lance Taylor
  2009-09-21 22:36   ` Gabriel Dos Reis
  0 siblings, 1 reply; 4+ messages in thread
From: Ian Lance Taylor @ 2009-09-21 21:56 UTC (permalink / raw)
  To: Florian Weimer; +Cc: gcc

Florian Weimer <fw@deneb.enyo.de> writes:

> G++ currently accepts the following code:
>
> char *
> alloc(unsigned a, unsigned b)
> {
>   typedef char array[a];
>   return &**(new array[b]);
> }
>
> Is this intentional?  The equivalent "new char[a][b]" is rejected (as
> required by the C++ standard).

Is there any reason that g++ should reject your sample program?

Because of the existence of operator new[], "new char[a][b]" quite a bit
harder to understand than your code is.

Ian

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: C++: variable length arrays and operator new[]
  2009-09-21 21:56 ` Ian Lance Taylor
@ 2009-09-21 22:36   ` Gabriel Dos Reis
  2009-09-22 17:03     ` Florian Weimer
  0 siblings, 1 reply; 4+ messages in thread
From: Gabriel Dos Reis @ 2009-09-21 22:36 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: Florian Weimer, gcc

On Mon, Sep 21, 2009 at 4:56 PM, Ian Lance Taylor <iant@google.com> wrote:
> Florian Weimer <fw@deneb.enyo.de> writes:
>
>> G++ currently accepts the following code:
>>
>> char *
>> alloc(unsigned a, unsigned b)
>> {
>>   typedef char array[a];
>>   return &**(new array[b]);
>> }
>>
>> Is this intentional?  The equivalent "new char[a][b]" is rejected (as
>> required by the C++ standard).
>
> Is there any reason that g++ should reject your sample program?

Yes: there is no obvious reason for gratuitous incompatibility in semantics.

>
> Because of the existence of operator new[], "new char[a][b]" quite a bit
> harder to understand than your code is.

But, new char[4][3] is OK.

FWIW, I do really find the VMT version far harder to understand.

>
> Ian
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: C++: variable length arrays and operator new[]
  2009-09-21 22:36   ` Gabriel Dos Reis
@ 2009-09-22 17:03     ` Florian Weimer
  0 siblings, 0 replies; 4+ messages in thread
From: Florian Weimer @ 2009-09-22 17:03 UTC (permalink / raw)
  To: gdr; +Cc: Ian Lance Taylor, gcc

* Gabriel Dos Reis:

>>> Is this intentional?  The equivalent "new char[a][b]" is rejected (as
>>> required by the C++ standard).
>>
>> Is there any reason that g++ should reject your sample program?
>
> Yes: there is no obvious reason for gratuitous incompatibility in
> semantics.

That, and it requires full saturating multiplication support at
run-time if we want to fix PR19351 in the most straightforward way (by
passing size_t(-1) to the underlying allocator function in case of
overflow).

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-09-22 17:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-09-20  9:59 C++: variable length arrays and operator new[] Florian Weimer
2009-09-21 21:56 ` Ian Lance Taylor
2009-09-21 22:36   ` Gabriel Dos Reis
2009-09-22 17:03     ` Florian Weimer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).