R
Roger Davis
I am trying to use nothrow new() and am encountering what seems
to be a bug in the SGI/Irix C++ environment. The following
program runs OK under Solaris and Linux, but dumps core at the
delete[] statement under Irix. Is this really an SGI implementation bug,
or have I done something stupid? (Other than trying to use nothrow
new(), that is ;-) )
#include <new>
#include <stdexcept>
std::nothrow_t NoThrow;
class Junk {
public:
Junk();
~Junk();
};
Junk::Junk() {
(void) fprintf(stderr, "constr\n"); (void) fflush(stderr);
}
Junk::~Junk() {
(void) fprintf(stderr, "destr\n"); (void) fflush(stderr);
}
main() {
Junk *jnk;
if ((jnk= new(NoThrow) Junk[5]) == (Junk *) 0) {
(void) fprintf(stderr, "memory allocation error\n");
exit(-1);
}
delete[] jnk;
}
My debugger stack looks like this:
_kill()
_raise()
abort()
_array_pointer_not_from_vec_new()
__array_delete_general2()
__vec_delete2()
main() <---- stopped on the delete[] statement
If I use regular new() instead, i.e.,
jnk= new Junk[5];
then the delete[] works OK under Irix. Do I need to be using some
special form of delete[] to indicate that the new() was called with
nothrow? I have seen no documentation anywhere that indicates that
I should, but maybe I am not looking in the right places.
I also tried
float *f;
f= new(NoThrow) float[100];
delete[] f;
under Irix and that works OK. The problem seems to occur only when
using delete[] on a non-primitive.
Thanks!
to be a bug in the SGI/Irix C++ environment. The following
program runs OK under Solaris and Linux, but dumps core at the
delete[] statement under Irix. Is this really an SGI implementation bug,
or have I done something stupid? (Other than trying to use nothrow
new(), that is ;-) )
#include <new>
#include <stdexcept>
std::nothrow_t NoThrow;
class Junk {
public:
Junk();
~Junk();
};
Junk::Junk() {
(void) fprintf(stderr, "constr\n"); (void) fflush(stderr);
}
Junk::~Junk() {
(void) fprintf(stderr, "destr\n"); (void) fflush(stderr);
}
main() {
Junk *jnk;
if ((jnk= new(NoThrow) Junk[5]) == (Junk *) 0) {
(void) fprintf(stderr, "memory allocation error\n");
exit(-1);
}
delete[] jnk;
}
My debugger stack looks like this:
_kill()
_raise()
abort()
_array_pointer_not_from_vec_new()
__array_delete_general2()
__vec_delete2()
main() <---- stopped on the delete[] statement
If I use regular new() instead, i.e.,
jnk= new Junk[5];
then the delete[] works OK under Irix. Do I need to be using some
special form of delete[] to indicate that the new() was called with
nothrow? I have seen no documentation anywhere that indicates that
I should, but maybe I am not looking in the right places.
I also tried
float *f;
f= new(NoThrow) float[100];
delete[] f;
under Irix and that works OK. The problem seems to occur only when
using delete[] on a non-primitive.
Thanks!