[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Vector new bug ??
From: |
André Pönitz |
Subject: |
Re: Vector new bug ?? |
Date: |
11 Oct 2001 07:30:47 GMT |
Günter Neiß <address@hidden> wrote:
> I found the following bug:
>
> Using some templates that uses:
>
> template<class T>
> ....
> t * p = new T[ size ];
>
>
> Everything works fine, as long as 'size' isn't 0.
Which version of g++ is that?
It seems to work in 2.95.2
> if( size == 0 )
> p = NULL;
> else
> p = new T[ size ];
> ...
>
> But I assume that this behaviour should already implemented inside
> (vector) new !
Note that there is a difference between an array of zero items and a null
pointer.
> I am not shure what the C++ standard says to this, but if it don't
> specify it, I assume returning NULL should be the default behaviour in
> this case ( as malloc( 0 ) does ).
Your assumption is wrong. From CD2 (similar wording in Final under 5.3.4.7)
5.3.4
8 When the value of the expression in a direct-new-declarator is zero,
the allocation function is called to allocate an array with no ele-
ments. The pointer returned by the new-expression is non-null and
distinct from the pointer to any other object.
Andre'
PS:
> application/x-pkcs7-signature; name="smime.p7s"
> Content-Transfer-Encoding: base64 Content-Disposition: attachment;
> filename="smime.p7s" Content-Description: Kryptographische Unterschrift
> mit S/MIME
[Is this really necessary?]
--
André Pönitz .............................................. address@hidden