When trying to compile this program --- class A { public: #ifdef SAFE A() : argc(0) { }; #else A() : argc(0), argv() { }; #endif private: int argc; char* argv[]; }; int main() { A y; } --- with g++ without -DSAFE, the compiler consumes all memory until it chokes: g++ argv.cpp -o argv -Wall virtual memory exhausted: Cannot allocate memory It does not happen when using "char**" as type. some info: uname -a Linux operator 2.4.20-4GB #1 Wed Oct 29 22:20:11 CET 2003 i686 i686 i386 GNU/Linux g++ -v Reading specs from /usr/lib/gcc-lib/i586-suse-linux/3.3.1/specs Configured with: ../configure --enable-threads=posix --prefix=/usr --with-local-prefix=/usr/local --infodir=/usr/share/info --mandir=/usr/share/man --libdir=/usr/lib --enable-languages=c,c++,f77,objc,java,ada --disable-checking --enable-libgcj --with-gxx-include-dir=/usr/include/g++ --with-slibdir=/lib --with-system-zlib --enable-shared --enable-__cxa_atexit i586-suse-linux Thread model: posix gcc version 3.3.1 (SuSE Linux)
Confirmed a regression from 3.2.3, I am not going to run Phil's regression hunter on this because it would cause problems for Phil's machine.
This should have been rejected just as ICC 6.0 (in strict ANSI mode only).
Note that the memory consumption happens while trying to intialize the array and taking (unsigned int)-1 as upper bound.#0 0x40093d45 in memset () from /lib/libc.so.6 #1 0x084f61a7 in ggc_alloc (size=67108852) at ../../gcc/ggc-page.c:1156 #2 0x0832ab45 in ggc_alloc_cleared (size=67108852) at ../../gcc/ggc-common.c:134 #3 0x0832abe2 in ggc_calloc (s1=16777213, s2=4) at ../../gcc/ggc-common.c:188 #4 0x085a12b9 in htab_expand (htab=0x40177780) at ../../libiberty/hashtab.c:393 #5 0x085a149d in htab_find_slot_with_hash (htab=0x40177780, element=0x5acac8fc, hash=140315878, insert=INSERT) at ../../libiberty/hashtab.c:510 #6 0x085a14cf in htab_find_slot (htab=0x40177780, element=0x5acac8fc, insert=INSERT) at ../../libiberty/hashtab.c:558 #7 0x082d294b in size_int_type_wide (number=6291408, type=0x401799b4) at ../../gcc/fold-const.c:1569 #8 0x082d1662 in int_const_binop (code=PLUS_EXPR, arg1=0x5acac8c0, arg2=0x4016d94c, notrunc=0) at ../../gcc/fold-const.c:1334 #9 0x082d2aa0 in size_binop (code=PLUS_EXPR, arg0=0x5acac8c0, arg1=0x4016d94c) at ../../gcc/fold-const.c:1609 #10 0x0815d7a0 in build_zero_init (type=0x4024372c, nelts=0x0, static_storage_p=false) at ../../gcc/cp/init.c:231 #11 0x0815d8dc in build_default_init (type=0x4024372c, nelts=0x0) at ../../gcc/cp/init.c:296 #12 0x0815dc81 in perform_member_init (member=0x40243798, init=0x0) at ../../gcc/cp/init.c:362 #13 0x0815ee30 in emit_mem_initializers (mem_inits=0x40238ed8) at ../../gcc/cp/init.c:694 #14 0x0817abe3 in finish_mem_initializers (mem_inits=0x40238e88) at ../../gcc/cp/semantics.c:1187 #15 0x08127ed8 in cp_parser_mem_initializer_list (parser=0x40242800) at ../../gcc/cp/parser.c:7063 #16 0x08127db7 in cp_parser_ctor_initializer_opt (parser=0x40242800) at ../../gcc/cp/parser.c:7020 #17 0x0812cdb5 in cp_parser_ctor_initializer_opt_and_function_body (parser=0x40242800) at ../../gcc/cp/parser.c:11183 #18 0x08131453 in cp_parser_function_definition_after_declarator (parser=0x40242800, inline_p=true) at ../../gcc/cp/parser.c:13989 #19 0x08132047 in cp_parser_late_parsing_for_member (parser=0x40242800, member_function=0x402433cc) at ../../gcc/cp/parser.c:14380 #20 0x0812db6b in cp_parser_class_specifier (parser=0x40242800) at ../../gcc/cp/parser.c:11650 #21 0x08129c5f in cp_parser_type_specifier (parser=0x40242800, flags=CP_PARSER_FLAGS_OPTIONAL, is_friend=false, is_declaration=true, declares_class_or_enum=0xbffff620, is_cv_qualifier=0xbffff61f) at ../../gcc/cp/parser.c:8541 #22 0x08127813 in cp_parser_decl_specifier_seq (parser=0x40242800, flags=CP_PARSER_FLAGS_OPTIONAL, attributes=0xbffff66c, declares_class_or_enum=0xbffff668) at ../../gcc/cp/parser.c:6652 #23 0x081274df in cp_parser_simple_declaration (parser=0x40242800, function_definition_allowed_p=true) at ../../gcc/cp/parser.c:6382 #24 0x081274ac in cp_parser_block_declaration (parser=0x40242800, statement_p=false) at ../../gcc/cp/parser.c:6342 #25 0x08127359 in cp_parser_declaration (parser=0x40242800) at ../../gcc/cp/parser.c:6262 #26 0x08127184 in cp_parser_declaration_seq_opt (parser=0x40242800) at ../../gcc/cp/parser.c:6171 #27 0x08122d82 in cp_parser_translation_unit (parser=0x40242800) at ../../gcc/cp/parser.c:2307 #28 0x0813315c in c_parse_file () at ../../gcc/cp/parser.c:15044 #29 0x081f4be8 in c_common_parse_file (set_yydebug=0) at ../../gcc/c-opts.c:1216 #30 0x084b9390 in compile_file () at ../../gcc/toplev.c:1804 #31 0x084be34e in do_compile () at ../../gcc/toplev.c:4611 #32 0x084be3e6 in toplev_main (argc=3, argv=0xbffff834) at ../../gcc/toplev.c:4651 #33 0x081f8fcf in main (argc=3, argv=0xbffff834) at ../../gcc/main.c:35 ibm:~ #
Subject: Bug 13574 CVSROOT: /cvs/gcc Module name: gcc Changes by: mmitchel@gcc.gnu.org 2004-01-16 19:28:11 Modified files: gcc/cp : ChangeLog decl.c init.c gcc/testsuite : ChangeLog Added files: gcc/testsuite/g++.dg/ext: array1.C Log message: PR c++/13574 * decl.c (compute_array_index_type): Fix grammar in comment. * init.c (build_zero_init): Handle zero-sized arrays correctly. PR c++/13574 * g++.dg/ext/array1.C: New test. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.3891&r2=1.3892 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl.c.diff?cvsroot=gcc&r1=1.1173&r2=1.1174 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/init.c.diff?cvsroot=gcc&r1=1.355&r2=1.356 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.3388&r2=1.3389 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/ext/array1.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
Fixed in GCC 3.4.
Subject: Bug 13574 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-3_3-branch Changes by: gdr@gcc.gnu.org 2004-01-21 08:06:38 Modified files: gcc/cp : ChangeLog decl.c init.c Added files: gcc/testsuite/g++.dg/ext: array1.C Log message: Backport from mainline 2004-01-16 Mark Mitchell <mark@codesourcery.com> PR c++/13574 * decl.c (compute_array_index_type): Fix grammar in comment. * init.c (build_zero_init): Handle zero-sized arrays correctly. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.3076.2.241&r2=1.3076.2.242 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.965.2.71&r2=1.965.2.72 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/init.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.299.2.12&r2=1.299.2.13 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/ext/array1.C.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=NONE&r2=1.1.6.1
Fixed with backport from 3.4.0