From: Jakub Jelinek Date: Mon, 25 Jun 2018 17:33:40 +0000 (+0200) Subject: backport: re PR c++/84874 (internal compiler error: in reshape_init_class, at cp... X-Git-Tag: releases/gcc-6.5.0~207 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=314ae10180b6e3348a11a4eb3392835f41e40521;p=thirdparty%2Fgcc.git backport: re PR c++/84874 (internal compiler error: in reshape_init_class, at cp/decl.c:5800) Backported from mainline 2018-03-16 Jakub Jelinek PR c++/84874 * decl.c (reshape_init_class): Don't assert d->cur->index == field if d->cur->index is a FIELD_DECL, instead set field to d->cur->index. * g++.dg/cpp1z/desig7.C: New test. From-SVN: r262077 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 99f8f149a1e0..c831f14f09c4 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,6 +1,12 @@ 2018-06-25 Jakub Jelinek Backported from mainline + 2018-03-16 Jakub Jelinek + + PR c++/84874 + * decl.c (reshape_init_class): Don't assert d->cur->index == field + if d->cur->index is a FIELD_DECL, instead set field to d->cur->index. + 2018-03-15 Jakub Jelinek PR c++/84222 diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index b86dabf24237..13b7000d6b47 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -5652,8 +5652,18 @@ reshape_init_class (tree type, reshape_iter *d, bool first_initializer_p, return error_mark_node; if (TREE_CODE (d->cur->index) == FIELD_DECL) - /* We already reshaped this. */ - gcc_assert (d->cur->index == field); + { + /* We already reshaped this. */ + if (field != d->cur->index) + { + tree id = DECL_NAME (d->cur->index); + gcc_assert (id); + gcc_checking_assert (lookup_field_1 (type, id, + /*want_type=*/false) + == d->cur->index); + field = d->cur->index; + } + } else if (TREE_CODE (d->cur->index) == IDENTIFIER_NODE) field = lookup_field_1 (type, d->cur->index, /*want_type=*/false); else diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 818d6b60c4c2..65efe2139901 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,6 +1,11 @@ 2018-06-25 Jakub Jelinek Backported from mainline + 2018-03-16 Jakub Jelinek + + PR c++/84874 + * g++.dg/cpp1z/desig7.C: New test. + 2018-03-15 Jakub Jelinek PR c++/79085 diff --git a/gcc/testsuite/g++.dg/cpp1z/desig7.C b/gcc/testsuite/g++.dg/cpp1z/desig7.C new file mode 100644 index 000000000000..83688375f784 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/desig7.C @@ -0,0 +1,18 @@ +// PR c++/84874 +// { dg-do compile { target c++11 } } +// { dg-options "" } + +struct A { int a, b; }; +struct B { A d; }; + +void +foo (B *x) +{ + *x = { .d = { .b = 5 } }; // { dg-message "non-trivial designated initializers not supported" } +} + +void +bar (A *x) +{ + *x = { .b = 6 }; // { dg-message "non-trivial designated initializers not supported" } +}