From bb7d75ffce7a2ca526229b579666ceae01805f69 Mon Sep 17 00:00:00 2001 From: Patrick Palka Date: Tue, 7 Feb 2017 02:20:48 +0000 Subject: [PATCH] re PR c++/79360 (ICE with NSDMI and enum in union) Fix PR c++/79360 gcc/cp/ChangeLog: PR c++/79360 * typeck2.c (process_init_constructor_union): Consider only FIELD_DECLs when looking for an NSDMI. gcc/testsuite/ChangeLog: PR c++/79360 * g++.dg/cpp1y/nsdmi-union2.C: New test. From-SVN: r245239 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/typeck2.c | 3 ++- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/cpp1y/nsdmi-union2.C | 12 ++++++++++++ 4 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp1y/nsdmi-union2.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 80f1113d837..85bb3b5736d 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2017-02-07 Patrick Palka + + PR c++/79360 + * typeck2.c (process_init_constructor_union): Consider only + FIELD_DECLs when looking for an NSDMI. + 2017-02-06 Jason Merrill PR c++/71193 - incomplete types in templates diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c index 014de5c66e3..1e0354d8a73 100644 --- a/gcc/cp/typeck2.c +++ b/gcc/cp/typeck2.c @@ -1510,7 +1510,8 @@ process_init_constructor_union (tree type, tree init, { for (tree field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field)) { - if (DECL_INITIAL (field)) + if (TREE_CODE (field) == FIELD_DECL + && DECL_INITIAL (field) != NULL_TREE) { CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (init), field, diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 57fe2417997..427615c511b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-02-07 Patrick Palka + + PR c++/79360 + * g++.dg/cpp1y/nsdmi-union2.C: New test. + 2017-02-06 Kito Cheng * lib/target-supports.exp: Define the RISC-V target. diff --git a/gcc/testsuite/g++.dg/cpp1y/nsdmi-union2.C b/gcc/testsuite/g++.dg/cpp1y/nsdmi-union2.C new file mode 100644 index 00000000000..08217d799db --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/nsdmi-union2.C @@ -0,0 +1,12 @@ +// PR c++/79360 +// { dg-do compile { target c++14 } } + +union U +{ + enum E { e }; +}; + +struct A +{ + U u{}; +}; -- 2.30.2