* Vector new bug ??
@ 2001-10-12 2:25 Günter NeiÃ
2001-10-12 2:55 ` Florian Weimer
0 siblings, 1 reply; 3+ messages in thread
From: Günter Neià@ 2001-10-12 2:25 UTC (permalink / raw)
To: gcc
Hi,
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.
In that case I got an exeption inside 'builin vector new' (shown by
gdb).
Ok, the workaroung is to check for this case:
...
T * p;
if( size == 0 )
p = NULL;
else
p = new T[ size ];
...
But I assume that this behaviour (or a similar one) should already
implemented inside (vector) new !
I assume this, because this code was ported from Borland C++ (and works
under MS-C++ as well).
I am not shure what the C++ standard says to this, but if it don't
specify it,
I assume returning NULL (or any unique pointer) should be the default
behaviour in this case
( as malloc( 0 ) does ).
...
Guenter
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Vector new bug ??
2001-10-12 2:25 Vector new bug ?? Günter NeiÃ
@ 2001-10-12 2:55 ` Florian Weimer
2001-10-12 6:45 ` Carlo Wood
0 siblings, 1 reply; 3+ messages in thread
From: Florian Weimer @ 2001-10-12 2:55 UTC (permalink / raw)
To: Günter NeiÃÂ; +Cc: gcc
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 714 bytes --]
Günter Neià <gneiss@schoenhofer.de> writes:
> Hi,
>
> 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.
>
> In that case I got an exeption inside 'builin vector new' (shown by
> gdb).
This is indeed a bug:
| When the value of the expression in a direct-new-declarator is zero,
| the allocation function is called to allocate an array with no
| elements. The pointer returned by the new-expression is non-null.
| [Note: If the library allocation function is called, the pointer
| returned is distinct from the pointer to any other object. ]
ISO/IEC 14882:1998, 5.3.4(7).
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Vector new bug ??
2001-10-12 2:55 ` Florian Weimer
@ 2001-10-12 6:45 ` Carlo Wood
0 siblings, 0 replies; 3+ messages in thread
From: Carlo Wood @ 2001-10-12 6:45 UTC (permalink / raw)
To: Florian Weimer
Cc: Günter NeiÃÂ, gcc
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 740 bytes --]
On Fri, Oct 12, 2001 at 12:10:40PM +0200, Florian Weimer wrote:
> Günter Neià <gneiss@schoenhofer.de> writes:
> > t * p = new T[ size ];
> > Everything works fine, as long as 'size' isn't 0.
> This is indeed a bug:
>
> | When the value of the expression in a direct-new-declarator is zero,
> | the allocation function is called to allocate an array with no
> | elements. The pointer returned by the new-expression is non-null.
> | [Note: If the library allocation function is called, the pointer
> | returned is distinct from the pointer to any other object. ]
>
> ISO/IEC 14882:1998, 5.3.4(7).
Weird that this is allowed, after all - zero elements for a normal
array isn't allowed either.
--
Carlo Wood <carlo@alinoe.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2001-10-12 6:45 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-10-12 2:25 Vector new bug ?? Günter NeiÃ
2001-10-12 2:55 ` Florian Weimer
2001-10-12 6:45 ` Carlo Wood
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).