[Bug c++/71516] New: ICE on invalid C++ code (invalid use of forward declared type) on x86_64-linux-gnu: Segmentation fault (program cc1plus)

su at cs dot ucdavis.edu gcc-bugzilla@gcc.gnu.org
Mon Jun 13 06:28:00 GMT 2016


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71516

            Bug ID: 71516
           Summary: ICE on invalid C++ code (invalid use of forward
                    declared type) on x86_64-linux-gnu: Segmentation fault
                    (program cc1plus)
           Product: gcc
           Version: 7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: su at cs dot ucdavis.edu
  Target Milestone: ---

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 {};


More information about the Gcc-bugs mailing list