This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PR c++/84593] ice on braced init with uninit ref field
- From: Alexandre Oliva <aoliva at redhat dot com>
- To: Jason Merrill <jason at redhat dot com>
- Cc: gcc-patches List <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 06 Mar 2018 03:14:34 -0300
- Subject: Re: [PR c++/84593] ice on braced init with uninit ref field
- Authentication-results: sourceware.org; auth=none
- References: <orbmg9pb95.fsf@lxoliva.fsfla.org> <CADzB+2n-9O4WFpoDz=6ZbOEE=GyE6P+xkKThcY+XMaeoLJrNyA@mail.gmail.com> <ork1uux63f.fsf@lxoliva.fsfla.org> <CADzB+2mKBW0ZCS2NKoQE+8exW+EKYWM5GesZrajaJnNRJe_+uA@mail.gmail.com>
On Mar 2, 2018, Jason Merrill <jason@redhat.com> wrote:
>> + gcc_assert (TREE_CODE (type) == REFERENCE_TYPE);
>> + init = fold (convert (type, integer_zero_node));
> Maybe build_zero_cst?
> OK either way.
Here's what I'm installing:
[PR c++/84593] ice on braced init with uninit ref field
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.
---
gcc/cp/init.c | 5 ++++-
gcc/testsuite/g++.dg/cpp1y/pr84593.C | 8 ++++++++
2 files changed, 12 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/g++.dg/cpp1y/pr84593.C
diff --git a/gcc/cp/init.c b/gcc/cp/init.c
index d0d14abdc9fa..15cee17c780c 100644
--- a/gcc/cp/init.c
+++ b/gcc/cp/init.c
@@ -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)
diff --git a/gcc/testsuite/g++.dg/cpp1y/pr84593.C b/gcc/testsuite/g++.dg/cpp1y/pr84593.C
new file mode 100644
index 000000000000..8aa869f19193
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/pr84593.C
@@ -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" }
--
Alexandre Oliva, freedom fighter http://FSFLA.org/~lxoliva/
You must be the change you wish to see in the world. -- Gandhi
Be Free! -- http://FSFLA.org/ FSF Latin America board member
Free Software Evangelist|Red Hat Brasil GNU Toolchain Engineer