This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Vector new bug ??


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]