From: Bernd Edlinger Date: Mon, 7 Jan 2019 17:08:51 +0000 (+0000) Subject: re PR c++/88261 (ICE: verify_gimple failed (error: non-trivial conversion at assignment)) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=08c35030c7ece1f7034d9bf7b6d3e94138ad3c68;p=gcc.git re PR c++/88261 (ICE: verify_gimple failed (error: non-trivial conversion at assignment)) PR c++/88261 PR c++/69338 PR c++/69696 PR c++/69697 * cp-tree.h (LOOKUP_ALLOW_FLEXARRAY_INIT): New flag value. * typeck2.c (digest_init_r): Raise an error for non-static initialization of a flexible array member. (process_init_constructor, massage_init_elt, process_init_constructor_array, process_init_constructor_record, process_init_constructor_union, process_init_constructor): Add the flags parameter and pass it thru. (store_init_value): Pass LOOKUP_ALLOW_FLEXARRAY_INIT parameter to digest_init_flags for static decls. gcc/testsuite: 2019-01-07 Bernd Edlinger PR c++/88261 PR c++/69338 PR c++/69696 PR c++/69697 * gcc.dg/array-6.c: Move from here ... * c-c++-common/array-6.c: ... to here and add some more test coverage. * g++.dg/pr69338.C: New test. * g++.dg/pr69697.C: Likewise. * g++.dg/ext/flexary32.C: Likewise. * g++.dg/ext/flexary3.C: Adjust test. * g++.dg/ext/flexary12.C: Likewise. * g++.dg/ext/flexary13.C: Likewise. * g++.dg/ext/flexary15.C: Likewise. * g++.dg/warn/Wplacement-new-size-1.C: Likewise. * g++.dg/warn/Wplacement-new-size-2.C: Likewise. * g++.dg/warn/Wplacement-new-size-6.C: Likewise. From-SVN: r267653 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index cbb70140c69..60c8ae1934e 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,19 @@ +2019-01-07 Bernd Edlinger + + PR c++/88261 + PR c++/69338 + PR c++/69696 + PR c++/69697 + * cp-tree.h (LOOKUP_ALLOW_FLEXARRAY_INIT): New flag value. + * typeck2.c (digest_init_r): Raise an error for non-static + initialization of a flexible array member. + (process_init_constructor, massage_init_elt, + process_init_constructor_array, process_init_constructor_record, + process_init_constructor_union, process_init_constructor): Add the + flags parameter and pass it thru. + (store_init_value): Pass LOOKUP_ALLOW_FLEXARRAY_INIT parameter to + digest_init_flags for static decls. + 2019-01-07 Jakub Jelinek PR c++/85052 diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 794849b5066..44739049b8d 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -5454,6 +5454,8 @@ enum overload_flags { NO_SPECIAL = 0, DTOR_FLAG, TYPENAME_FLAG }; #define LOOKUP_NO_NON_INTEGRAL (LOOKUP_NO_RVAL_BIND << 1) /* Used for delegating constructors in order to diagnose self-delegation. */ #define LOOKUP_DELEGATING_CONS (LOOKUP_NO_NON_INTEGRAL << 1) +/* Allow initialization of a flexible array members. */ +#define LOOKUP_ALLOW_FLEXARRAY_INIT (LOOKUP_DELEGATING_CONS << 1) #define LOOKUP_NAMESPACES_ONLY(F) \ (((F) & LOOKUP_PREFER_NAMESPACES) && !((F) & LOOKUP_PREFER_TYPES)) diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c index 03b24a94ede..ecc313b2355 100644 --- a/gcc/cp/typeck2.c +++ b/gcc/cp/typeck2.c @@ -35,7 +35,7 @@ along with GCC; see the file COPYING3. If not see #include "gcc-rich-location.h" static tree -process_init_constructor (tree type, tree init, int nested, +process_init_constructor (tree type, tree init, int nested, int flags, tsubst_flags_t complain); @@ -817,8 +817,12 @@ store_init_value (tree decl, tree init, vec** cleanups, int flags) if (flags & LOOKUP_ALREADY_DIGESTED) value = init; else - /* Digest the specified initializer into an expression. */ - value = digest_init_flags (type, init, flags, tf_warning_or_error); + { + if (TREE_STATIC (decl)) + flags |= LOOKUP_ALLOW_FLEXARRAY_INIT; + /* Digest the specified initializer into an expression. */ + value = digest_init_flags (type, init, flags, tf_warning_or_error); + } if (TREE_CODE (type) == ARRAY_TYPE && TYPE_STRING_FLAG (TREE_TYPE (type)) @@ -1068,8 +1072,18 @@ digest_init_r (tree type, tree init, int nested, int flags, { if (nested && !TYPE_DOMAIN (type)) /* C++ flexible array members have a null domain. */ - pedwarn (loc, OPT_Wpedantic, - "initialization of a flexible array member"); + { + if (flags & LOOKUP_ALLOW_FLEXARRAY_INIT) + pedwarn (loc, OPT_Wpedantic, + "initialization of a flexible array member"); + else + { + if (complain & tf_error) + error_at (loc, "non-static initialization of" + " a flexible array member"); + return error_mark_node; + } + } tree typ1 = TYPE_MAIN_VARIANT (TREE_TYPE (type)); if (char_type_p (typ1) @@ -1193,7 +1207,8 @@ digest_init_r (tree type, tree init, int nested, int flags, if (BRACE_ENCLOSED_INITIALIZER_P (stripped_init) && !TYPE_NON_AGGREGATE_CLASS (type)) - return process_init_constructor (type, stripped_init, nested, complain); + return process_init_constructor (type, stripped_init, nested, flags, + complain); else { if (COMPOUND_LITERAL_P (stripped_init) && code == ARRAY_TYPE) @@ -1291,9 +1306,12 @@ picflag_from_initializer (tree init) /* Adjust INIT for going into a CONSTRUCTOR. */ static tree -massage_init_elt (tree type, tree init, int nested, tsubst_flags_t complain) +massage_init_elt (tree type, tree init, int nested, int flags, + tsubst_flags_t complain) { - init = digest_init_r (type, init, nested ? 2 : 1, LOOKUP_IMPLICIT, complain); + flags &= LOOKUP_ALLOW_FLEXARRAY_INIT; + flags |= LOOKUP_IMPLICIT; + init = digest_init_r (type, init, nested ? 2 : 1, flags, complain); /* Strip a simple TARGET_EXPR when we know this is an initializer. */ if (SIMPLE_TARGET_EXPR_P (init)) init = TARGET_EXPR_INITIAL (init); @@ -1311,11 +1329,11 @@ massage_init_elt (tree type, tree init, int nested, tsubst_flags_t complain) which describe the initializers. */ static int -process_init_constructor_array (tree type, tree init, int nested, +process_init_constructor_array (tree type, tree init, int nested, int flags, tsubst_flags_t complain) { unsigned HOST_WIDE_INT i, len = 0; - int flags = 0; + int picflags = 0; bool unbounded = false; constructor_elt *ce; vec *v = CONSTRUCTOR_ELTS (init); @@ -1365,7 +1383,8 @@ process_init_constructor_array (tree type, tree init, int nested, ce->index = error_mark_node; gcc_assert (ce->value); ce->value - = massage_init_elt (TREE_TYPE (type), ce->value, nested, complain); + = massage_init_elt (TREE_TYPE (type), ce->value, nested, flags, + complain); gcc_checking_assert (ce->value == error_mark_node @@ -1373,7 +1392,7 @@ process_init_constructor_array (tree type, tree init, int nested, (strip_array_types (TREE_TYPE (type)), strip_array_types (TREE_TYPE (ce->value))))); - flags |= picflag_from_initializer (ce->value); + picflags |= picflag_from_initializer (ce->value); } /* No more initializers. If the array is unbounded, we are done. Otherwise, @@ -1389,7 +1408,8 @@ process_init_constructor_array (tree type, tree init, int nested, we can't rely on the back end to do it for us, so make the initialization explicit by list-initializing from T{}. */ next = build_constructor (init_list_type_node, NULL); - next = massage_init_elt (TREE_TYPE (type), next, nested, complain); + next = massage_init_elt (TREE_TYPE (type), next, nested, flags, + complain); if (initializer_zerop (next)) /* The default zero-initialization is fine for us; don't add anything to the CONSTRUCTOR. */ @@ -1406,7 +1426,7 @@ process_init_constructor_array (tree type, tree init, int nested, if (next) { - flags |= picflag_from_initializer (next); + picflags |= picflag_from_initializer (next); if (len > i+1 && (initializer_constant_valid_p (next, TREE_TYPE (next)) == null_pointer_node)) @@ -1426,7 +1446,7 @@ process_init_constructor_array (tree type, tree init, int nested, } CONSTRUCTOR_ELTS (init) = v; - return flags; + return picflags; } /* Subroutine of process_init_constructor, which will process an initializer @@ -1434,7 +1454,7 @@ process_init_constructor_array (tree type, tree init, int nested, the initializers. */ static int -process_init_constructor_record (tree type, tree init, int nested, +process_init_constructor_record (tree type, tree init, int nested, int flags, tsubst_flags_t complain) { vec *v = NULL; @@ -1449,7 +1469,7 @@ process_init_constructor_record (tree type, tree init, int nested, gcc_assert (!TYPE_POLYMORPHIC_P (type)); restart: - int flags = 0; + int picflags = 0; unsigned HOST_WIDE_INT idx = 0; int designator_skip = -1; /* Generally, we will always have an index for each initializer (which is @@ -1517,7 +1537,7 @@ process_init_constructor_record (tree type, tree init, int nested, if (ce) { gcc_assert (ce->value); - next = massage_init_elt (type, next, nested, complain); + next = massage_init_elt (type, next, nested, flags, complain); ++idx; } } @@ -1546,7 +1566,8 @@ process_init_constructor_record (tree type, tree init, int nested, for us, so build up TARGET_EXPRs. If the type in question is a class, just build one up; if it's an array, recurse. */ next = build_constructor (init_list_type_node, NULL); - next = massage_init_elt (TREE_TYPE (field), next, nested, complain); + next = massage_init_elt (TREE_TYPE (field), next, nested, flags, + complain); /* Warn when some struct elements are implicitly initialized. */ if ((complain & tf_warning) @@ -1597,7 +1618,7 @@ process_init_constructor_record (tree type, tree init, int nested, /* If this is a bitfield, now convert to the lowered type. */ if (type != TREE_TYPE (field)) next = cp_convert_and_check (TREE_TYPE (field), next, complain); - flags |= picflag_from_initializer (next); + picflags |= picflag_from_initializer (next); CONSTRUCTOR_APPEND_ELT (v, field, next); } @@ -1653,7 +1674,7 @@ process_init_constructor_record (tree type, tree init, int nested, } CONSTRUCTOR_ELTS (init) = v; - return flags; + return picflags; } /* Subroutine of process_init_constructor, which will process a single @@ -1661,7 +1682,7 @@ process_init_constructor_record (tree type, tree init, int nested, which describe the initializer. */ static int -process_init_constructor_union (tree type, tree init, int nested, +process_init_constructor_union (tree type, tree init, int nested, int flags, tsubst_flags_t complain) { constructor_elt *ce; @@ -1749,7 +1770,7 @@ process_init_constructor_union (tree type, tree init, int nested, if (ce->value && ce->value != error_mark_node) ce->value = massage_init_elt (TREE_TYPE (ce->index), ce->value, nested, - complain); + flags, complain); return picflag_from_initializer (ce->value); } @@ -1769,40 +1790,43 @@ process_init_constructor_union (tree type, tree init, int nested, of error. */ static tree -process_init_constructor (tree type, tree init, int nested, +process_init_constructor (tree type, tree init, int nested, int flags, tsubst_flags_t complain) { - int flags; + int picflags; gcc_assert (BRACE_ENCLOSED_INITIALIZER_P (init)); if (TREE_CODE (type) == ARRAY_TYPE || VECTOR_TYPE_P (type)) - flags = process_init_constructor_array (type, init, nested, complain); + picflags = process_init_constructor_array (type, init, nested, flags, + complain); else if (TREE_CODE (type) == RECORD_TYPE) - flags = process_init_constructor_record (type, init, nested, complain); + picflags = process_init_constructor_record (type, init, nested, flags, + complain); else if (TREE_CODE (type) == UNION_TYPE) - flags = process_init_constructor_union (type, init, nested, complain); + picflags = process_init_constructor_union (type, init, nested, flags, + complain); else gcc_unreachable (); - if (flags & PICFLAG_ERRONEOUS) + if (picflags & PICFLAG_ERRONEOUS) return error_mark_node; TREE_TYPE (init) = type; if (TREE_CODE (type) == ARRAY_TYPE && TYPE_DOMAIN (type) == NULL_TREE) cp_complete_array_type (&TREE_TYPE (init), init, /*do_default=*/0); - if (flags & PICFLAG_SIDE_EFFECTS) + if (picflags & PICFLAG_SIDE_EFFECTS) { TREE_CONSTANT (init) = false; TREE_SIDE_EFFECTS (init) = true; } - else if (flags & PICFLAG_NOT_ALL_CONSTANT) + else if (picflags & PICFLAG_NOT_ALL_CONSTANT) /* Make sure TREE_CONSTANT isn't set from build_constructor. */ TREE_CONSTANT (init) = false; else { TREE_CONSTANT (init) = 1; - if (!(flags & PICFLAG_NOT_ALL_SIMPLE)) + if (!(picflags & PICFLAG_NOT_ALL_SIMPLE)) TREE_STATIC (init) = 1; } return init; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 13d8c065b11..4bb56349adf 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,22 @@ +2019-01-07 Bernd Edlinger + + PR c++/88261 + PR c++/69338 + PR c++/69696 + PR c++/69697 + * gcc.dg/array-6.c: Move from here ... + * c-c++-common/array-6.c: ... to here and add some more test coverage. + * g++.dg/pr69338.C: New test. + * g++.dg/pr69697.C: Likewise. + * g++.dg/ext/flexary32.C: Likewise. + * g++.dg/ext/flexary3.C: Adjust test. + * g++.dg/ext/flexary12.C: Likewise. + * g++.dg/ext/flexary13.C: Likewise. + * g++.dg/ext/flexary15.C: Likewise. + * g++.dg/warn/Wplacement-new-size-1.C: Likewise. + * g++.dg/warn/Wplacement-new-size-2.C: Likewise. + * g++.dg/warn/Wplacement-new-size-6.C: Likewise. + 2019-01-07 Richard Earnshaw * gcc.target/aarch64/subs_compare_2.c: Make '#' immediate prefix diff --git a/gcc/testsuite/c-c++-common/array-6.c b/gcc/testsuite/c-c++-common/array-6.c new file mode 100644 index 00000000000..f3f2eda4ae7 --- /dev/null +++ b/gcc/testsuite/c-c++-common/array-6.c @@ -0,0 +1,47 @@ +/* PR c/5597 */ +/* { dg-do compile } */ +/* { dg-options "" } */ + +/* Verify that GCC forbids non-static initialization of + flexible array members. */ + +struct str { int len; char s[]; }; + +struct str a = { 2, "a" }; + +void foo() +{ + static struct str b = { 2, "b" }; + struct str c = { 2, "c" }; /* { dg-error "(non-static)|(near initialization)" } */ + struct str d = (struct str) { 2, "d" }; /* { dg-error "(non-static)|(near initialization)" } */ + struct str e = (struct str) { d.len, "e" }; /* { dg-error "(non-static)|(initialization)" } */ +} + +struct str f = { 0, {} }; + +void bar() +{ + static struct str g = { 0, {} }; + struct str h = { 0, {} }; /* { dg-error "(non-static)|(near initialization)" } */ + struct str i = (struct str) { 0, {} }; /* { dg-error "(non-static)|(near initialization)" } */ + struct str j = (struct str) { i.len, {} }; /* { dg-error "(non-static)|(initialization)" } */ +} + +struct str k = { 0 }; + +void baz() +{ + static struct str l = { 0 }; + struct str m = { 0 }; + struct str n = (struct str) { 0 }; + struct str o = (struct str) { n.len }; +} + +struct str p = {}; + +void qux() +{ + static struct str q = {}; + struct str r = {}; + struct str s = (struct str) {}; +} diff --git a/gcc/testsuite/g++.dg/ext/flexary12.C b/gcc/testsuite/g++.dg/ext/flexary12.C index 61726f63f28..b0964948731 100644 --- a/gcc/testsuite/g++.dg/ext/flexary12.C +++ b/gcc/testsuite/g++.dg/ext/flexary12.C @@ -12,7 +12,7 @@ struct A { void f1 () { // This is the meat of the test from c++/69290: - struct A a + static struct A a = { "c" }; // { dg-error "invalid conversion from .const char\\*. to .int." } (void)&a; @@ -27,13 +27,13 @@ struct B { void f2 () { - struct B b1 + static struct B b1 = { 0, "c" }; // { dg-error "invalid conversion from .const char\\*. to .int." } (void)&b1; const char s[] = "c"; - struct B b2 + static struct B b2 = { 0, s }; // { dg-error "invalid conversion from .const char\\*. to .int." } (void)&b2; @@ -57,7 +57,7 @@ struct C { void f3 () { - struct C cd + static struct C cd = { "c" }; // { dg-error "cannot convert .const char\\*. to .double." } (void)&cd; diff --git a/gcc/testsuite/g++.dg/ext/flexary13.C b/gcc/testsuite/g++.dg/ext/flexary13.C index f1f4e22a3ff..7c67d09ee5a 100644 --- a/gcc/testsuite/g++.dg/ext/flexary13.C +++ b/gcc/testsuite/g++.dg/ext/flexary13.C @@ -19,33 +19,33 @@ int main () ASSERT (s.n == 0); } { - Ax s = + static Ax s = { 0, { } }; // dg-warning "initialization of a flexible array member" } ASSERT (s.n == 0); } { - Ax s = + static Ax s = { 1, { 2 } }; // dg-warning "initialization of a flexible array member" } ASSERT (s.n == 1 && s.a [0] == 2); } { - Ax s = + static Ax s = { 2, { 3, 4 } }; // dg-warning "initialization of a flexible array member" } ASSERT (s.n = 2 && s.a [0] == 3 && s.a [1] == 4); } { - Ax s = + static Ax s = { 123, i }; // dg-warning "initialization of a flexible array member" } ASSERT (s.n == 123 && s.a [0] == i); } { - Ax s = + static Ax s = { 456, { i } }; // dg-warning "initialization of a flexible array member" } ASSERT (s.n == 456 && s.a [0] == i); } { int j = i + 1, k = j + 1; - Ax s = + static Ax s = { 3, { i, j, k } }; // dg-warning "initialization of a flexible array member" } ASSERT (s.n == 3 && s.a [0] == i && s.a [1] == j && s.a [2] == k); } diff --git a/gcc/testsuite/g++.dg/ext/flexary15.C b/gcc/testsuite/g++.dg/ext/flexary15.C index c03a60e7b50..da5f5f43123 100644 --- a/gcc/testsuite/g++.dg/ext/flexary15.C +++ b/gcc/testsuite/g++.dg/ext/flexary15.C @@ -10,5 +10,5 @@ struct S { void foo (const char *a) { - const S s = { 1, { a, "b" } }; // { dg-warning "invalid conversion" } + static const S s = { 1, { a, "b" } }; // { dg-warning "invalid conversion" } } diff --git a/gcc/testsuite/g++.dg/ext/flexary3.C b/gcc/testsuite/g++.dg/ext/flexary3.C index c7c0e793355..34b17254f8c 100644 --- a/gcc/testsuite/g++.dg/ext/flexary3.C +++ b/gcc/testsuite/g++.dg/ext/flexary3.C @@ -17,5 +17,6 @@ struct s { int main() { struct s s = { .c = 0 }; // { dg-error "initializer" } + // { dg-error "non-static initialization of a flexible array member" "" { target *-*-* } .-1 } return 0; } diff --git a/gcc/testsuite/g++.dg/ext/flexary32.C b/gcc/testsuite/g++.dg/ext/flexary32.C new file mode 100644 index 00000000000..7ca78b19d36 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/flexary32.C @@ -0,0 +1,19 @@ +/* { dg-do compile { target c++11 } } */ +/* { dg-options -Wno-pedantic } */ + +struct str { int len; char s[]; }; + +struct foo { + str x = {3, {1,2,3}}; /* { dg-error "(non-static)|(initialization)" } */ + foo() {} +}; + +struct bar { + static constexpr str x = {3, {1,2,3}}; + bar() {} +}; + +struct baz { + str x = {3}; + baz() {} +}; diff --git a/gcc/testsuite/g++.dg/pr69338.C b/gcc/testsuite/g++.dg/pr69338.C new file mode 100644 index 00000000000..8b1351b93d7 --- /dev/null +++ b/gcc/testsuite/g++.dg/pr69338.C @@ -0,0 +1,23 @@ +/* { dg-do compile { target c++11 } } */ +/* { dg-additional-options "-Wno-pedantic" } */ + +struct A { char i, a[]; }; + +void foo() +{ + struct A a0 = { 3, "AB" }; /* { dg-error "(non-static)|(initialization)" } */ +} + +struct A a1 = { 3, "AB" }; /* { dg-bogus "(non-static)|(initialization)" } */ + +struct A a2 = (struct A){ 3, "AB" }; /* { dg-error "(non-static)|(initialization)" } */ + +struct B1 { + A a3; + B1 (): a3 { 3, "AB" } { } /* { dg-error "(non-static)|(initialization)" } */ +} b1; + +struct B2 { + A a4; + B2 (): a4 ((struct A){ 3, "AB" }) { } /* { dg-error "(non-static)|(initialization)" } */ +} b2; diff --git a/gcc/testsuite/g++.dg/pr69697.C b/gcc/testsuite/g++.dg/pr69697.C new file mode 100644 index 00000000000..b0b72365faa --- /dev/null +++ b/gcc/testsuite/g++.dg/pr69697.C @@ -0,0 +1,7 @@ +/* { dg-do compile { target c++11 } } */ +/* { dg-additional-options "-Wno-pedantic" } */ + +int i; +struct A { int n, a[]; } + a = i ? A({ 1, { 2 } }) /* { dg-error "(non-static)|(initialization)" } */ + : A({ 2, { 3, 4 } }); /* { dg-error "(non-static)|(initialization)" } */ diff --git a/gcc/testsuite/g++.dg/warn/Wplacement-new-size-1.C b/gcc/testsuite/g++.dg/warn/Wplacement-new-size-1.C index 716986d4664..d2ec608afd4 100644 --- a/gcc/testsuite/g++.dg/warn/Wplacement-new-size-1.C +++ b/gcc/testsuite/g++.dg/warn/Wplacement-new-size-1.C @@ -28,7 +28,7 @@ void fAx (Ax *px, Ax &rx) void fAx2 () { - Ax ax2 = { 1, { 2, 3 } }; + static Ax ax2 = { 1, { 2, 3 } }; new (ax2.a) Int16; new (ax2.a) Int32; // { dg-warning "placement" } @@ -82,7 +82,7 @@ void fBx (BAx *pbx, BAx &rbx) void fBx1 () { - BAx bax1 = { 1, /* Ax = */ { 2, /* a[] = */ {} } }; + static BAx bax1 = { 1, /* Ax = */ { 2, /* a[] = */ {} } }; new (bax1.ax.a) char; // { dg-warning "placement" } new (bax1.ax.a) char[2]; // { dg-warning "placement" } diff --git a/gcc/testsuite/g++.dg/warn/Wplacement-new-size-2.C b/gcc/testsuite/g++.dg/warn/Wplacement-new-size-2.C index 3d470747e24..e00515eeaa9 100644 --- a/gcc/testsuite/g++.dg/warn/Wplacement-new-size-2.C +++ b/gcc/testsuite/g++.dg/warn/Wplacement-new-size-2.C @@ -33,13 +33,13 @@ void fAx (Ax *px, Ax &rx) void fAx2 () { // Initialization of non-static objects with flexible array members - // isn't allowed in C and should perhaps be disallowed in C++ as + // isn't allowed in C and had to be be disallowed in C++ as // well to avoid c++/69696 - incorrect initialization of block-scope // flexible array members. - Ax ax2 = { 1, { 2, 3 } }; + Ax ax2 = { 1, { 2, 3 } }; // { dg-error "non-static initialization of a flexible array member" } - new (ax2.a) Int16; - new (ax2.a) Int16[1]; + new (ax2.a) Int16; // { dg-warning "placement" } + new (ax2.a) Int16[1]; // { dg-warning "placement" } new (ax2.a) Int16[2]; // { dg-warning "placement" } new (ax2.a) Int32; // { dg-warning "placement" } new (ax2.a) Int32[2]; // { dg-warning "placement" } @@ -140,7 +140,7 @@ void fBx (BAx *pbx, BAx &rbx) void fBx1 () { - BAx bax1 = { 1, /* Ax = */ { 2, /* a[] = */ {} } }; + static BAx bax1 = { 1, /* Ax = */ { 2, /* a[] = */ {} } }; new (bax1.ax.a) char; // { dg-warning "placement" } new (bax1.ax.a) char[2]; // { dg-warning "placement" } diff --git a/gcc/testsuite/g++.dg/warn/Wplacement-new-size-6.C b/gcc/testsuite/g++.dg/warn/Wplacement-new-size-6.C index 06dfb3a0ba0..b6a72b18f6a 100644 --- a/gcc/testsuite/g++.dg/warn/Wplacement-new-size-6.C +++ b/gcc/testsuite/g++.dg/warn/Wplacement-new-size-6.C @@ -15,7 +15,7 @@ struct BAx { int i; Ax ax; }; void fBx1 () { - BAx bax1 = { 1, /* Ax = */ { 2, /* a[] = */ { 3 } } }; // { dg-error "initialization of flexible array member in a nested context" } + static BAx bax1 = { 1, /* Ax = */ { 2, /* a[] = */ { 3 } } }; // { dg-error "initialization of flexible array member in a nested context" } new (bax1.ax.a) char; // { dg-warning "placement" } new (bax1.ax.a) char[2]; // { dg-warning "placement" } @@ -25,7 +25,7 @@ void fBx1 () void fBx2 () { - BAx bax2 = { 1, /* Ax = */ { 2, /* a[] = */ { 3, 4 } } }; // { dg-error "initialization of flexible array member in a nested context" } + static BAx bax2 = { 1, /* Ax = */ { 2, /* a[] = */ { 3, 4 } } }; // { dg-error "initialization of flexible array member in a nested context" } new (bax2.ax.a) char; // { dg-warning "placement" } new (bax2.ax.a) char[2]; // { dg-warning "placement" } @@ -37,7 +37,7 @@ void fBx2 () void fBx3 () { - BAx bax2 = { 1, /* Ax = */ { 3, /* a[] = */ { 4, 5, 6 } } }; // { dg-error "initialization of flexible array member in a nested context" } + static BAx bax2 = { 1, /* Ax = */ { 3, /* a[] = */ { 4, 5, 6 } } }; // { dg-error "initialization of flexible array member in a nested context" } new (bax2.ax.a) char; // { dg-warning "placement" } new (bax2.ax.a) char[2]; // { dg-warning "placement" } diff --git a/gcc/testsuite/gcc.dg/array-6.c b/gcc/testsuite/gcc.dg/array-6.c deleted file mode 100644 index 6ef64625b96..00000000000 --- a/gcc/testsuite/gcc.dg/array-6.c +++ /dev/null @@ -1,18 +0,0 @@ -/* PR c/5597 */ -/* { dg-do compile } */ -/* { dg-options "" } */ - -/* Verify that GCC forbids non-static initialization of - flexible array members. */ - -struct str { int len; char s[]; }; - -struct str a = { 2, "a" }; - -void foo() -{ - static struct str b = { 2, "b" }; - struct str c = { 2, "c" }; /* { dg-error "(non-static)|(near initialization)" } */ - struct str d = (struct str) { 2, "d" }; /* { dg-error "(non-static)|(near initialization)" } */ - struct str e = (struct str) { d.len, "e" }; /* { dg-error "(non-static)|(initialization)" } */ -}