re PR c++/79360 (ICE with NSDMI and enum in union)
authorPatrick Palka <ppalka@gcc.gnu.org>
Tue, 7 Feb 2017 02:20:48 +0000 (02:20 +0000)
committerPatrick Palka <ppalka@gcc.gnu.org>
Tue, 7 Feb 2017 02:20:48 +0000 (02:20 +0000)
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
gcc/cp/typeck2.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp1y/nsdmi-union2.C [new file with mode: 0644]

index 80f1113d8379fa4e669d2e8796f29e08141f0c27..85bb3b5736d85da2884988267978f8f020f0294d 100644 (file)
@@ -1,3 +1,9 @@
+2017-02-07  Patrick Palka  <ppalka@gcc.gnu.org>
+
+       PR c++/79360
+       * typeck2.c (process_init_constructor_union): Consider only
+       FIELD_DECLs when looking for an NSDMI.
+
 2017-02-06  Jason Merrill  <jason@redhat.com>
 
        PR c++/71193 - incomplete types in templates
index 014de5c66e316f0ebeb739f98e8f3c0be72f5e43..1e0354d8a73ea50267c0495ca92a43e33c7da821 100644 (file)
@@ -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,
index 57fe2417997e747066757e27e57e8a3980e8c51f..427615c511be3f454b19e7506c012df1a4a9a136 100644 (file)
@@ -1,3 +1,8 @@
+2017-02-07  Patrick Palka  <ppalka@gcc.gnu.org>
+
+       PR c++/79360
+       * g++.dg/cpp1y/nsdmi-union2.C: New test.
+
 2017-02-06  Kito Cheng  <kito.cheng@gmail.com>
 
        * 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 (file)
index 0000000..08217d7
--- /dev/null
@@ -0,0 +1,12 @@
+// PR c++/79360
+// { dg-do compile { target c++14 } }
+
+union U
+{
+  enum E { e };
+};
+
+struct A
+{
+  U u{};
+};