The following C++ code causes an ICE when compiled with the current GCC trunk on x86_64-linux-gnu in both 32-bit and 64-bit modes. This is a regression from 6.1.x. $ g++-trunk -v Using built-in specs. COLLECT_GCC=g++-trunk COLLECT_LTO_WRAPPER=/usr/local/gcc-trunk/libexec/gcc/x86_64-pc-linux-gnu/7.0.0/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: ../gcc-source-trunk/configure --enable-languages=c,c++,lto --prefix=/usr/local/gcc-trunk --disable-bootstrap Thread model: posix gcc version 7.0.0 20160612 (experimental) [trunk revision 237336] (GCC) $ $ g++-6.1 -c small.cpp small.cpp:8:6: error: variable ‘A B::a’ has initializer but incomplete type A B::a = A(); ^ small.cpp:8:12: error: invalid use of incomplete type ‘class A’ A B::a = A(); ^ small.cpp:1:7: note: forward declaration of ‘class A’ class A; ^ $ $ g++-trunk -c small.cpp small.cpp:8:6: error: variable ‘A B::a’ has initializer but incomplete type A B::a = A(); ^ small.cpp:8:12: error: invalid use of incomplete type ‘class A’ A B::a = A(); ^ small.cpp:1:7: note: forward declaration of ‘class A’ class A; ^ small.cpp:10:7: internal compiler error: tree check: expected class ‘type’, have ‘exceptional’ (error_mark) in complete_vars, at cp/decl.c:15032 class A {}; ^ 0x1055277 tree_class_check_failed(tree_node const*, tree_code_class, char const*, int, char const*) ../../gcc-source-trunk/gcc/tree.c:9803 0x694fcc tree_class_check ../../gcc-source-trunk/gcc/tree.h:3153 0x694fcc complete_vars(tree_node*) ../../gcc-source-trunk/gcc/cp/decl.c:15032 0x74db1c finish_struct_1(tree_node*) ../../gcc-source-trunk/gcc/cp/class.c:7081 0x74f574 finish_struct(tree_node*, tree_node*) ../../gcc-source-trunk/gcc/cp/class.c:7265 0x788f1c cp_parser_class_specifier_1 ../../gcc-source-trunk/gcc/cp/parser.c:21368 0x788f1c cp_parser_class_specifier ../../gcc-source-trunk/gcc/cp/parser.c:21596 0x788f1c cp_parser_type_specifier ../../gcc-source-trunk/gcc/cp/parser.c:15836 0x79d9d3 cp_parser_decl_specifier_seq ../../gcc-source-trunk/gcc/cp/parser.c:12758 0x7aaec1 cp_parser_simple_declaration ../../gcc-source-trunk/gcc/cp/parser.c:12299 0x7ab311 cp_parser_block_declaration ../../gcc-source-trunk/gcc/cp/parser.c:12246 0x7b46f0 cp_parser_declaration ../../gcc-source-trunk/gcc/cp/parser.c:12143 0x7b31c4 cp_parser_declaration_seq_opt ../../gcc-source-trunk/gcc/cp/parser.c:12022 0x7b34f8 cp_parser_translation_unit ../../gcc-source-trunk/gcc/cp/parser.c:4324 0x7b34f8 c_parse_file() ../../gcc-source-trunk/gcc/cp/parser.c:37486 0x917072 c_common_parse_file() ../../gcc-source-trunk/gcc/c-family/c-opts.c:1064 Please submit a full bug report, with preprocessed source if appropriate. Please include the complete backtrace with any bug report. See <http://gcc.gnu.org/bugs.html> for instructions. $ --------------------- class A; class B { static A a; }; A B::a = A(); class A {};
Confirmed.
Started with r214353.
Created attachment 38696 [details] gcc7-pr71516.patch Untested fix.
Author: jakub Date: Tue Jun 14 14:33:11 2016 New Revision: 237445 URL: https://gcc.gnu.org/viewcvs?rev=237445&root=gcc&view=rev Log: PR c++/71516 * decl.c (complete_vars): Handle gracefully type == error_mark_node. * g++.dg/init/pr71516.C: New test. Added: trunk/gcc/testsuite/g++.dg/init/pr71516.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/decl.c trunk/gcc/testsuite/ChangeLog
Author: jakub Date: Tue Jun 14 14:47:17 2016 New Revision: 237450 URL: https://gcc.gnu.org/viewcvs?rev=237450&root=gcc&view=rev Log: PR c++/71516 * decl.c (complete_vars): Handle gracefully type == error_mark_node. * g++.dg/init/pr71516.C: New test. Added: branches/gcc-6-branch/gcc/testsuite/g++.dg/init/pr71516.C Modified: branches/gcc-6-branch/gcc/cp/ChangeLog branches/gcc-6-branch/gcc/cp/decl.c branches/gcc-6-branch/gcc/testsuite/ChangeLog
Fixed for 6.2+ so far.
Author: jakub Date: Thu Jul 7 12:44:33 2016 New Revision: 238097 URL: https://gcc.gnu.org/viewcvs?rev=238097&root=gcc&view=rev Log: Backported from mainline 2016-06-14 Jakub Jelinek <jakub@redhat.com> PR c++/71516 * decl.c (complete_vars): Handle gracefully type == error_mark_node. * g++.dg/init/pr71516.C: New test. Added: branches/gcc-5-branch/gcc/testsuite/g++.dg/init/pr71516.C Modified: branches/gcc-5-branch/gcc/cp/ChangeLog branches/gcc-5-branch/gcc/cp/decl.c branches/gcc-5-branch/gcc/testsuite/ChangeLog
Fixed.