[PR c++/84593] ice on braced init with uninit ref field
authorAlexandre Oliva <aoliva@redhat.com>
Tue, 6 Mar 2018 06:24:53 +0000 (06:24 +0000)
committerAlexandre Oliva <aoliva@gcc.gnu.org>
Tue, 6 Mar 2018 06:24:53 +0000 (06:24 +0000)
If an initializer expr is to be NULL in a ctor initializer list, we
ICE in picflag_from_initializer and elsewhere.

If we're missing an initializer for a reference field, we report the
error, but then build a zero initializer to avoid the ICE.

for  gcc/cp/ChangeLog

PR c++/84593
* init.c (build_zero_init_1): Zero-initialize references.

for  gcc/testsuite/ChangeLog

PR c++/84593
* g++.dg/cpp1y/pr84593.C: New.

From-SVN: r258270

gcc/cp/ChangeLog
gcc/cp/init.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp1y/pr84593.C [new file with mode: 0644]

index cbacda6..3623405 100644 (file)
@@ -1,5 +1,8 @@
 2018-03-06  Alexandre Oliva <aoliva@redhat.com>
 
+       PR c++/84593
+       * init.c (build_zero_init_1): Zero-initialize references.
+
        PR c++/84492
        * semantics.c (finish_stmt_expr_expr): Reject unresolved
        overloads used as stmt expr values.
index d0d14ab..15cee17 100644 (file)
@@ -284,7 +284,10 @@ build_zero_init_1 (tree type, tree nelts, bool static_storage_p,
   else if (VECTOR_TYPE_P (type))
     init = build_zero_cst (type);
   else
-    gcc_assert (TREE_CODE (type) == REFERENCE_TYPE);
+    {
+      gcc_assert (TREE_CODE (type) == REFERENCE_TYPE);
+      init = build_zero_cst (type);
+    }
 
   /* In all cases, the initializer is a constant.  */
   if (init)
index e3e3262..9c94d36 100644 (file)
@@ -1,5 +1,8 @@
 2018-03-06  Alexandre Oliva <aoliva@redhat.com>
 
+       PR c++/84593
+       * g++.dg/cpp1y/pr84593.C: New.
+
        PR c++/84492
        * g++.dg/pr84492.C: New.
 
diff --git a/gcc/testsuite/g++.dg/cpp1y/pr84593.C b/gcc/testsuite/g++.dg/cpp1y/pr84593.C
new file mode 100644 (file)
index 0000000..8aa869f
--- /dev/null
@@ -0,0 +1,8 @@
+// PR c++/84593
+// { dg-do compile { target c++14 } }
+
+struct a {
+  int x;
+  int c = 0;
+  int &b;
+} c = {}; // { dg-error "uninitialized reference" }