This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: missing g++ warning about bad allocation
- From: Ian Lance Taylor <iant at google dot com>
- To: "Martin Ettl" <ettl dot martin at gmx dot de>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Thu, 02 Jul 2009 14:02:43 -0700
- Subject: Re: missing g++ warning about bad allocation
- References: <20090702202446.227060@gmx.net>
"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