public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* 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

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).