Bug 71516 - [5 Regression] ICE on invalid C++ code (invalid use of forward declared type) on x86_64-linux-gnu: Segmentation fault (program cc1plus)
Summary: [5 Regression] ICE on invalid C++ code (invalid use of forward declared type)...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 7.0
: P4 normal
Target Milestone: 7.0
Assignee: Jakub Jelinek
URL:
Keywords: error-recovery, ice-on-invalid-code
Depends on:
Blocks:
 
Reported: 2016-06-13 06:27 UTC by Zhendong Su
Modified: 2016-07-07 13:19 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 6.1.0
Known to fail:
Last reconfirmed: 2016-06-13 00:00:00


Attachments
gcc7-pr71516.patch (598 bytes, patch)
2016-06-13 15:18 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Zhendong Su 2016-06-13 06:27:56 UTC
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 {};
Comment 1 Martin Liška 2016-06-13 07:57:15 UTC
Confirmed.
Comment 2 Jakub Jelinek 2016-06-13 12:57:43 UTC
Started with r214353.
Comment 3 Jakub Jelinek 2016-06-13 15:18:11 UTC
Created attachment 38696 [details]
gcc7-pr71516.patch

Untested fix.
Comment 4 Jakub Jelinek 2016-06-14 14:33:42 UTC
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
Comment 5 Jakub Jelinek 2016-06-14 14:47:49 UTC
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
Comment 6 Jakub Jelinek 2016-06-14 14:54:15 UTC
Fixed for 6.2+ so far.
Comment 7 Jakub Jelinek 2016-07-07 12:45:05 UTC
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
Comment 8 Jakub Jelinek 2016-07-07 13:19:00 UTC
Fixed.