From 9ca4280a921b0094c7ef131c5c8a63b451ab9a05 Mon Sep 17 00:00:00 2001 From: Martin Sebor Date: Thu, 5 Mar 2020 09:37:25 -0700 Subject: [PATCH] Backport fix for PR c++/93753 from trunk. gcc/cp/ChangeLog: Backport from trunk. 2020-02-21 Martin Sebor PR c++/93753 * class.c (check_flexarrays): Tighten up a test for potential members of anonymous structs or unions. gcc/testsuite/ChangeLog: Backport from trunk. 2020-02-21 Martin Sebor PR c++/93753 * g++.dg/ext/flexary36.C: New test. --- gcc/cp/ChangeLog | 9 ++ gcc/cp/class.c | 2 + gcc/testsuite/ChangeLog | 8 ++ gcc/testsuite/g++.dg/ext/flexary36.C | 123 +++++++++++++++++++++++++++ 4 files changed, 142 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/flexary36.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index bf0d9b3f2cbd..437df4d0829a 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,12 @@ +2020-03-05 Martin Sebor + + Backport from trunk. + 2020-02-21 Martin Sebor + + PR gcov-profile/93753 + * class.c (check_flexarrays): Tighten up a test for potential members + of anonymous structs or unions. + 2020-03-05 Jason Merrill PR c++/90338 diff --git a/gcc/cp/class.c b/gcc/cp/class.c index 46fac4ef38e4..6b57184e0815 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -6937,6 +6937,8 @@ check_flexarrays (tree t, flexmems_t *fmem /* = NULL */, /* Is the type unnamed (and therefore a member of it potentially an anonymous struct or union)? */ bool maybe_anon_p = TYPE_UNNAMED_P (t); + if (tree ctx = maybe_anon_p ? TYPE_CONTEXT (t) : NULL_TREE) + maybe_anon_p = RECORD_OR_UNION_TYPE_P (ctx); /* Search the members of the current (possibly derived) class, skipping unnamed structs and unions since those could be anonymous. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index ec8328c01e29..08fa68673df9 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,11 @@ +2020-03-05 Martin Sebor + + Backport from trunk. + 2020-02-21 Martin Sebor + + PR gcov-profile/93753 + * g++.dg/ext/flexary36.C: New test. + 2020-03-05 Paul Thomas Backport from trunk diff --git a/gcc/testsuite/g++.dg/ext/flexary36.C b/gcc/testsuite/g++.dg/ext/flexary36.C new file mode 100644 index 000000000000..5bb827cfd0e0 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/flexary36.C @@ -0,0 +1,123 @@ +/* PR c++/93753 - ICE on a flexible array followed by a member in + an anonymous struct with an initializer + { dg-do compile } + { dg-options "-Wall -Wno-unused-variable" } */ + +struct { + int a[]; // { dg-error "flexible array member '::a' not at end of 'struct'" } + int b; +} ax; + +struct { + int a[]; // { dg-error "flexible array member '::a' not at end of 'struct'" } + int b; +} bx = { }; + +struct { + int a[]; // { dg-error "flexible array member '::a' not at end of 'struct'" } + int b; +} cx = { 0 }; + +struct { + int a[]; // { dg-error "flexible array member '::a' not at end of 'struct'" } + int b; +} dx = { 1 }; + + +union { + int a[]; // { dg-error "flexible array member in union" } + int b; +} du = { 1 }; + + +struct A { + int a[]; // { dg-error "flexible array member 'A::a' not at end of 'struct A'" } + int b; +} a; + +struct B { + int a[]; // { dg-error "flexible array member 'B::a' not at end of 'struct B'" } + int b; +} b = { }; + +struct C { + int a[]; // { dg-error "flexible array member 'C::a' not at end of 'struct C'" } + int b; +} c = { 0 }; + +struct D { + int a[]; // { dg-error "flexible array member 'D::a' not at end of 'struct D'" } + int b; +} d = { 1 }; + + +struct E { + struct { + int a[]; // { dg-error " not at end " } + int b; + } e = { 1 }; // { dg-error "non-static initialization of a flexible array member" } +}; + +struct G { + struct { + int a[]; // { dg-error " not at end " } + int b; + }; +} g = { 1 }; // { dg-error "initialization of flexible array member in a nested context" } + +struct H { + int i; + struct { + int a[]; // { dg-error " not at end " } + int b; + }; +} h = { 1 }; + +namespace { + +struct { + int a[]; // { dg-error " not at end of " } + int b; +} ax; + +struct { + int a[]; // { dg-error " not at end " } + int b; +} bx = { }; + +struct { + int a[]; // { dg-error " not at end " } + int b; +} cx = { 0 }; + +struct { + int a[]; // { dg-error " not at end " } + int b; +} dx = { 1 }; + + +struct A { + int a[]; // { dg-error " not at end of 'struct {anonymous}::A'" } + int b; +} a; + +struct B { + int a[]; // { dg-error " not at end of 'struct {anonymous}::B'" } + int b; +} b = { }; + +struct C { + int a[]; // { dg-error " not at end of 'struct {anonymous}::C'" } + int b; +} c = { 0 }; + +struct D { + int a[]; // { dg-error " not at end of 'struct {anonymous}::D'" } + int b; +} d = { 1 }; + +} + +// { dg-prune-output "unnamed type with no linkage used to declare variable" } +// { dg-prune-output "non-static data member initializers" } +// { dg-prune-output "extended initializer lists" } -- 2.47.3