re PR c/5597 ([regression from 2.95.3] Initialization of flexible char array member segfaults)
PR c/5597 * c-typeck.c (process_init_element): Flag non-static initialization of a flexible array member as illegal. From-SVN: r51156
This commit is contained in:
parent
bac015e792
commit
eba8099439
|
@ -1,3 +1,9 @@
|
|||
2002-03-21 Eric Botcazou <ebotcazou@multimania.com>
|
||||
|
||||
PR c/5597
|
||||
* c-typeck.c (process_init_element): Flag non-static
|
||||
initialization of a flexible array member as illegal.
|
||||
|
||||
2002-03-22 Alan Modra <amodra@bigpond.net.au>
|
||||
|
||||
* config/rs6000/t-linux64: New.
|
||||
|
@ -10,19 +16,19 @@
|
|||
|
||||
2002-03-21 Aldy Hernandez <aldyh@redhat.com>
|
||||
|
||||
* langhooks.c (lhd_tree_inlining_cannot_inline_tree_fn): Check
|
||||
flag_really_no_inline instead of optimize == 0.
|
||||
* langhooks.c (lhd_tree_inlining_cannot_inline_tree_fn): Check
|
||||
flag_really_no_inline instead of optimize == 0.
|
||||
|
||||
* c-objc-common.c (c_cannot_inline_tree_fn): Same.
|
||||
* c-objc-common.c (c_cannot_inline_tree_fn): Same.
|
||||
|
||||
* cp/tree.c (cp_cannot_inline_tree_fn): Same.
|
||||
* cp/tree.c (cp_cannot_inline_tree_fn): Same.
|
||||
|
||||
* flags.h (flag_really_no_inline): New.
|
||||
* flags.h (flag_really_no_inline): New.
|
||||
|
||||
* c-common.c (c_common_post_options): Initialzie
|
||||
flag_really_no_inline.
|
||||
* c-common.c (c_common_post_options): Initialzie
|
||||
flag_really_no_inline.
|
||||
|
||||
* toplev.c (flag_really_no_inline): New.
|
||||
* toplev.c (flag_really_no_inline): New.
|
||||
|
||||
2002-03-21 Jakub Jelinek <jakub@redhat.com>
|
||||
|
||||
|
|
|
@ -6537,6 +6537,16 @@ process_init_element (value)
|
|||
fieldtype = TYPE_MAIN_VARIANT (fieldtype);
|
||||
fieldcode = TREE_CODE (fieldtype);
|
||||
|
||||
/* Error for non-static initialization of a flexible array member. */
|
||||
if (fieldcode == ARRAY_TYPE
|
||||
&& !require_constant_value
|
||||
&& TYPE_SIZE (fieldtype) == NULL_TREE
|
||||
&& TREE_CHAIN (constructor_fields) == NULL_TREE)
|
||||
{
|
||||
error_init ("non-static initialization of a flexible array member");
|
||||
break;
|
||||
}
|
||||
|
||||
/* Accept a string constant to initialize a subarray. */
|
||||
if (value != 0
|
||||
&& fieldcode == ARRAY_TYPE
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
/* 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)" } */
|
||||
}
|
Loading…
Reference in New Issue