From: Jakub Jelinek Date: Tue, 14 Jun 2016 14:33:11 +0000 (+0200) Subject: re PR c++/71516 (ICE on invalid C++ code (invalid use of forward declared type) on... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=abe7f8287ef2a19f089b135dc3d0b1f666615485;p=gcc.git re PR c++/71516 (ICE on invalid C++ code (invalid use of forward declared type) on x86_64-linux-gnu: Segmentation fault (program cc1plus)) PR c++/71516 * decl.c (complete_vars): Handle gracefully type == error_mark_node. * g++.dg/init/pr71516.C: New test. From-SVN: r237445 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 64acdc81458..d006305bdc0 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2016-06-14 Jakub Jelinek + + PR c++/71516 + * decl.c (complete_vars): Handle gracefully type == error_mark_node. + 2016-06-14 Paolo Carlini * typeck2.c (digest_init_r): Use EXPR_LOC_OR_LOC on init. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 415689f535f..20e7307ddad 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -15029,8 +15029,9 @@ complete_vars (tree type) tree var = iv->decl; tree type = TREE_TYPE (var); - if (TYPE_MAIN_VARIANT (strip_array_types (type)) - == iv->incomplete_type) + if (type != error_mark_node + && (TYPE_MAIN_VARIANT (strip_array_types (type)) + == iv->incomplete_type)) { /* Complete the type of the variable. The VAR_DECL itself will be laid out in expand_expr. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 3addc24998f..0e3c9cd7738 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-06-14 Jakub Jelinek + + PR c++/71516 + * g++.dg/init/pr71516.C: New test. + 2016-06-14 Paolo Carlini * g++.dg/init/array46.C: New. diff --git a/gcc/testsuite/g++.dg/init/pr71516.C b/gcc/testsuite/g++.dg/init/pr71516.C new file mode 100644 index 00000000000..0b9aec41707 --- /dev/null +++ b/gcc/testsuite/g++.dg/init/pr71516.C @@ -0,0 +1,10 @@ +// PR c++/71516 +// { dg-do compile } + +struct A; // { dg-message "forward declaration of" } +struct B +{ + static A a; +}; +A B::a = A(); // { dg-error "has initializer but incomplete type|invalid use of incomplete type" } +struct A {};