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]

Re: Bug or WAD?


> From: Leo Comitale <comitale@ca.ibm.com>
> To: <egcs@cygnus.com>
> Date: Tue, 24 Nov 1998 11:49:42 -0500

>   void * operator new(unsigned long size)
>     { return (void *) 0; };

> Instead of just returning NULL, our code uses a malloc-like call to
> allocate storage for the new object.  In one of our testcases this
> call is forced to fail returning NULL to simulate an out-of-memory
> situation.  On most platforms (including AIX, Solaris, HP-UX,
> Windows NT, OS/2, etc) this does NOT result in a catastrophic error.
> However on Linux using egcs, it seems the object constructor is
> still being called and the program dies with a memory access
> violation.

> Can anyone tell me if this is "working as designed" or perhaps this
> is a small bug?

A small bug, in your program.  New is required to return a pointer to
memory for the constructor to build an object in, you violated that
requirement.  Your violation is what causes the problem in your
running program.

Try a newer book that describes new and nothrow...


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