This is the mail archive of the gcc-help@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]
Other format: [Raw text]

Re: missing g++ warning about bad allocation


Ok thanks, 

i was not aware of -Wconversion flag. Never the less i was wondering that this code was compilable. Because, allocting a negative amount of memory does not make senense. Anyway, thanks for the help.

Best regards

Martin 
-------- Original-Nachricht --------
> Datum: Thu, 02 Jul 2009 14:23:00 -0700
> Von: Ian Lance Taylor <iant@google.com>
> An: "Martin Ettl" <ettl.martin@gmx.de>
> CC: gcc-help@gcc.gnu.org
> Betreff: Re: missing g++  warning about bad allocation

> "Martin Ettl" <ettl.martin@gmx.de> writes:
> 
> > yes i know. This is a rather unusual case. It seems to me that there is
> a signed integer variable used for allocation (new[signed integer] and
> malloc (signed integer)) in the implementation of gcc/g++... why not using an
> unsigned integer and this error can be avoided. But this is just a
> thought....
> 
> Actually, that's a good point.  Both malloc and new take unsigned
> arguments, and I do get a warning using -Wconversion.  -Wconversion is
> not included in -Wall because it generates too many false positives for
> existing code.
> 
> Ian
> 
> > -------- Original-Nachricht --------
> >> Datum: Thu, 02 Jul 2009 14:02:43 -0700
> >> Von: Ian Lance Taylor <iant@google.com>
> >> An: "Martin Ettl" <ettl.martin@gmx.de>
> >> CC: gcc-help@gcc.gnu.org
> >> Betreff: Re: missing g++  warning about bad allocation
> >
> >> "Martin Ettl" <ettl.martin@gmx.de> writes:
> >> 
> >> > compiling the following code with g++-4.4.0 on Ubuntu Linux (Jaunty):
> >> >
> >> >
> >> > int main()
> >> > {
> >> > 	double * d = new double[-100];
> >> > }
> >> >
> >> > compiles without warning. I used following compilation flags: (-W
> -Wall
> >> -Wextra -pedantic).
> >> >
> >> > Exectuting the compiled programm gives:
> >> >
> >> > ./test 
> >> > terminate called after throwing an instance of 'std::bad_alloc'
> >> >   what():  std::bad_alloc
> >> > Aborted
> >> >
> >> > Is there a reason why g++ does not warn about this? 
> >> 
> >> I doubt there is an explicit reason that there is no warning.  I expect
> >> that nobody has ever been moved to add a warning for such an unusual
> >> case.  gcc also does not warn about malloc(-100).
> >> 
> >> Ian

-- 
Neu: GMX Doppel-FLAT mit Internet-Flatrate + Telefon-Flatrate
für nur 19,99 Euro/mtl.!* http://portal.gmx.net/de/go/dsl02


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