In C++, according to Stroustrup, enums can grow to sizeof(int). On this machine, sizeof(int)==4, but I when exploring the maximum size enum value g++ would honour, I got an ICE. The following code (put it in a file called enum.C) COMPILES with given command line and runs $ cat enum.C <<EOF enum test { acceptable = 0x7fffffffffffffff, unacceptable = 0xffffffffffffffff }; int main() { test t = acceptable, u = unacceptable; return 0; } EOF $ g++ -save-temps enum.C -o enum $ ./enum Release: 3.3 and 3.4 (CVS 20030503) Environment: Linux 2.4.18-17.7.x i686 How-To-Repeat: Replace line in enum.C that says: acceptable = 0x7fffffffffffffff, with the following line: acceptable = -1, and attempt to compile with command line as given.
Fix: Don't use ridiculous enum values? Is that sufficient, or should the compiler be able to pick this up?
State-Changed-From-To: open->analyzed State-Changed-Why: Confirmed. To make it clearer, the following code snippet ICEs GCC: ------------------------------------------------ enum test { one = -1, two = 0xffffffffffffffff }; ------------------------------------------------ pr10796.cpp:4: error: integer constant is too large for "long" type pr10796.cpp:5: internal compiler error: Segmentation fault Please submit a full bug report, I call the code legal because it would be possible to use "unsigned long long" as underlying type for such an enumerator (at least on x86, where its size is 8 bytes), even if I don't know what the C++ ABI says about this. Anyway, we shouldn't segfault on this for sure. It's a regression wrt 2.95 (which was failing gracefully).
It still fails on the mainline (20030607): 0x080820ad in finish_enum (enumtype=0x400a83cc) at /home/gates/pinskia/src/gnu/ gcc/src/gcc/cp/decl.c:13100 warning: Source file is more recent than executable. 13100 layout_type (enumtype); (gdb) bt #0 0x080820ad in finish_enum (enumtype=0x400a83cc) at /home/gates/pinskia/src/ gnu/gcc/src/gcc/cp/decl.c:13100 #1 0x080fe776 in cp_parser_enum_specifier (parser=0x400aa480) at /home/gates/ pinskia/src/gnu/gcc/src/gcc/cp/parser.c:8995 #2 0x080fe09c in cp_parser_type_specifier (parser=0x400aa480, flags= CP_PARSER_FLAGS_OPTIONAL, is_friend=false, is_declaration=true, declares_class_or_enum=0xbffec2fe, is_cv_qualifier=0xbffec2ff) at /home/gates/pinskia/ src/gnu/gcc/src/gcc/cp/parser.c:8470 #3 0x080fc5ad in cp_parser_decl_specifier_seq (parser=0x400aa480, flags= CP_PARSER_FLAGS_OPTIONAL, attributes=0xbffec348, declares_class_or_enum= 0xbffec34f) at /home/gates/pinskia/src/gnu/gcc/src/gcc/cp/parser.c:6802 #4 0x080fc2ac in cp_parser_simple_declaration (parser=0x400aa480, function_definition_allowed_p=true) at /home/gates/pinskia/src/gnu/gcc/src/gcc/cp/ parser.c:6548 #5 0x080fc1d4 in cp_parser_block_declaration (parser=0x400aa480, statement_p= false) at /home/gates/pinskia/src/gnu/gcc/src/gcc/cp/parser.c:6508 #6 0x080fc08d in cp_parser_declaration (parser=0x400aa480) at /home/gates/pinskia/ src/gnu/gcc/src/gcc/cp/parser.c:6428 #7 0x080fbf38 in cp_parser_declaration_seq_opt (parser=0x400aa480) at /home/gates/ pinskia/src/gnu/gcc/src/gcc/cp/parser.c:6337 #8 0x080f7962 in cp_parser_translation_unit (parser=0x400aa480) at /home/gates/ pinskia/src/gnu/gcc/src/gcc/cp/parser.c:2256 #9 0x08105592 in yyparse () at /home/gates/pinskia/src/gnu/gcc/src/gcc/cp/ parser.c:14671 #10 0x0817da76 in c_common_parse_file (set_yydebug=0) at /home/gates/pinskia/src/ gnu/gcc/src/gcc/c-opts.c:1394 #11 0x083aab3a in compile_file () at /home/gates/pinskia/src/gnu/gcc/src/gcc/ toplev.c:2213 #12 0x083b0c77 in do_compile () at /home/gates/pinskia/src/gnu/gcc/src/gcc/ toplev.c:5743 #13 0x083b0ce9 in toplev_main (argc=0, argv=0x0) at /home/gates/pinskia/src/gnu/gcc/ src/gcc/toplev.c:5772 #14 0x081819eb in main (argc=0, argv=0x0) at /home/gates/pinskia/src/gnu/gcc/src/gcc/ main.c:37 (gdb) p debug_tree(enumtype) <enumeral_type 0x400a83cc test TI size <integer_cst 0x4004eb18 type <integer_type 0x4005a948 bit_size_type> constant 128> unit size <integer_cst 0x4004eb2c type <integer_type 0x4005a8dc unsigned int> constant 16> align 128 symtab 0 alias set -1 precision 65 min <integer_cst 0x400ad050 0x8000000000000000> max <integer_cst 0x400ad064 0x7fffffffffffffff> values <tree_list 0x40099fa0 purpose <identifier_node 0x400aa500 onebindings <0x40099f8c>local bindings < (nil)>> value <integer_cst 0x400ad000 constant tree_0 -1> chain <tree_list 0x40099fdc purpose <identifier_node 0x400aa540 twobindings <0x40099fc8>local bindings < (nil)>> value <integer_cst 0x400ad014 constant -1>>> chain <type_decl 0x400a8438 test>>
Subject: Bug 10796 CVSROOT: /cvs/gcc Module name: gcc Changes by: mmitchel@gcc.gnu.org 2003-06-27 21:21:08 Modified files: gcc/cp : ChangeLog decl.c gcc/testsuite : ChangeLog Added files: gcc/testsuite/g++.dg/init: enum1.C Log message: PR c++/10796 * decl.c (finish_enum): Implement DR377. * decl.c (cp_finish_decl): Don't make variables with reference type readonly while they are being initialized. PR c++/10796 * g++.dg/init/enum1.C: New test. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.3460&r2=1.3461 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl.c.diff?cvsroot=gcc&r1=1.1072&r2=1.1073 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.2809&r2=1.2810 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/init/enum1.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
Subject: Bug 10796 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-3_3-branch Changes by: mmitchel@gcc.gnu.org 2003-06-27 21:28:15 Modified files: gcc/cp : ChangeLog decl.c gcc/testsuite : ChangeLog Added files: gcc/testsuite/g++.dg/init: enum1.C Log message: PR c++/10796 * decl.c (finish_enum): Implement DR377. * decl.c (cp_finish_decl): Don't make variables with reference type readonly while they are being initialized. PR c++/10796 * g++.dg/init/enum1.C: New test. 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.165&r2=1.3076.2.166 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.52&r2=1.965.2.53 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.2261.2.205&r2=1.2261.2.206 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/init/enum1.C.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=NONE&r2=1.1.2.1
Fixed in GCC 3.3.1, GCC 3.4.
Subject: Bug 10796 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-3_3-branch Changes by: mmitchel@gcc.gnu.org 2003-07-25 00:31:02 Modified files: gcc/cp : ChangeLog call.c class.c cp-tree.h decl.c init.c method.c gcc/testsuite : ChangeLog Added files: gcc/testsuite/g++.dg/inherit: access5.C gcc/testsuite/g++.dg/init: enum2.C Log message: PR c++/10796 * decl.c (finish_enum): Make sure the underlying integer type has the same precision as some full integer type. Reverts part 2003-06-27's patch that didn't play any role in fixing the PR. * cp-tree.h (convert_to_base_statically): Declare. * call.c (build_special_member_call): Convert INSTANCE to the base type. * class.c (convert_to_base_statically): New method. * init.c (construct_virtual_base): Use it. * method.c (do_build_assign_ref): Fix typo in comment. * g++.dg/init/enum2.C: New. * g++.dg/inherit/access5.C: New test. 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.188&r2=1.3076.2.189 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/call.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.341.2.27&r2=1.341.2.28 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/class.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.499.2.16&r2=1.499.2.17 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/cp-tree.h.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.776.2.29&r2=1.776.2.30 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.57&r2=1.965.2.58 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.8&r2=1.299.2.9 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/method.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.237.4.2&r2=1.237.4.3 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.2261.2.244&r2=1.2261.2.245 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/inherit/access5.C.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=NONE&r2=1.1.4.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/init/enum2.C.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=NONE&r2=1.1.2.1