Article View: gnu.g++.bug
Article #917Re: g++ 2.2.2 runs constructor even if operator new() returns 0
From: Eric Valette
Date: Mon, 07 Sep 1992 17:13
Date: Mon, 07 Sep 1992 17:13
62 lines
2630 bytes
2630 bytes
>This behavior is under consideration by the ANSI C++ committee, they >are thinking about defining things such that new should never return >0. It would throw an exception instead. This has long been recognized >by g++ as the proper way to do things, and hence its past and current >behavior. > >I am inclided not to consider this a bug, until ANSI C++ decides it is. > >For now, I would recommend that you try and code your software in such >a way that it will work or be easy to change, either way ANSI decides. > >As a practical matter, you can do something like: > > p = (void *) malloc (sz); > if (p == 0) > (*__new_handler) (); > return p; Enough! I have seen this bug reported since G++ 1.37.2. I do not want to protect EACH constructor by code like: if (this == 0) return; nor do I want do use setjump/longjump to avoid going into the constructor. I know (as operating system writter) that many people use C++ to write embedded system where they redefine operator new for each class as a poll allocator. It is not because a pool allocator fails that you must stop your application and thus control must be given to user. A *very* simple way is to return zero and let the user decide what to do. FLAME ON FURTHERMORE THE CFRONT COMPILER DO THINGS OTHERWAY AND AS FAR AS I KNOW IT IS *THE* REFERENCE FOR C++ (except for exception :-)) FLAME OFF I am amazed you use ARM to argue because it is clear that people never read it before implementing G++. In particular, some people shoulkd have read it before implementing MI to understand impact on virtual functions... Frankly spealing I use all other GNU stuff (gemacs(1.55.1), gdb (4.5), gcc (2.2.2) but G++ is far to have the quality of other GNU tools : I never manged to compile the chorus kernel with GCC 2.x nor G++ 1.40. Otherwyse, I would be glad to propose FSF stuff to univercity. I speak for my own ... __ / ` Eric Valette /-- __ o _. Chorus Systemes (___, / (_(_(__ 6 avenue Gustave Eiffel F-78182, St-Quentin-en-Yvelines-Cedex Tel: +33 (1) 30 64 82 00 Fax: +33 (1) 30 57 00 66 E-mail: ev@chorus.fr
Technical Details
Message-ID:
<9209071313.AA03475@larsen.chorus.fr>Path:
arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!chorus.FR!evShow Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!chorus.FR!ev From: ev@chorus.FR (Eric Valette) Subject: Re: g++ 2.2.2 runs constructor even if operator new() returns 0 Message-ID: <9209071313.AA03475@larsen.chorus.fr> Sender: gnulists@ai.mit.edu Organization: GNUs Not Usenet Distribution: gnu Date: Mon, 7 Sep 1992 17:13:52 GMT Approved: bug-g++@prep.ai.mit.edu Lines: 67