This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: g++ uses infinite memory with unusual 'new' statement
- From: LLeweLLyn Reese <llewelly at lifesupport dot shutdown dot com>
- To: Paul Dubuc <pdubuc at cas dot org>
- Cc: gcc-help <gcc-help at gcc dot gnu dot org>, gcc-bugs at gcc dot gnu dot org
- Date: 10 Aug 2003 19:52:20 -0700
- Subject: Re: g++ uses infinite memory with unusual 'new' statement
- References: <3F302446.2060004@cas.org>
Paul Dubuc <pdubuc@cas.org> writes:
> This bug is simlar to #11282 in the GCC Bugzilla database, but It may
> have a different cause. The following program causes g++ 3.3 to loop
> (with no error or warning messages) using up all virtual memory.
This is a bug. I think you should file a bug report. Link to #11282 in
your report, and then it will be easy for the gcc developers to
determine if it is a duplicate, but I do not think it is; the code
you give below is AFAIK well-defined.
>
> int
> main()
> {
> int i = 16;
> char* heap_area = new char [i]();
> }
>
> Is line 5 valid C++ with the parens? I've never see new called this
> way, but it compiled fine with g++ 2.95.3. If the parens are valid,
> what do they mean?
They mean the array of char is default-initialized. See
5.3.4/15, second bullet.
>
> With g++ 3.2.3 I get the following error:
>
> z.cc: In function `int main()':
> z.cc:5: variable-sized object of type `char[i]' may not be initialized
>
> With 3.3 the code compiles fine when the parens are removed from line
> 5 or if a literal constant is used in place of 'i'.
[snip]