From: jsm28 Date: Sun, 19 Apr 2009 20:38:53 +0000 (+0000) Subject: PR c/37481 X-Git-Tag: upstream/4.9.2~36664 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fe49e5885b98c3e5b9a8c63f00db4cd9a08a9c9b;p=platform%2Fupstream%2Flinaro-gcc.git PR c/37481 * c-typeck.c (digest_init): Check for initializing an array with a string literal. testsuite: * gcc.dg/c99-flex-array-7.c: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@146359 138bc75d-0d04-0410-961f-82ee72b054a4 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 01488bf..6b45179 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,11 @@ 2009-04-19 Joseph Myers + PR c/37481 + * c-typeck.c (digest_init): Check for initializing an array with a + string literal. + +2009-04-19 Joseph Myers + PR c/19771 * c-semantics.c (pop_stmt_list): Propagate STATEMENT_LIST_HAS_LABEL to parent statement list. diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c index 821f4ce..96b1a5d 100644 --- a/gcc/c-typeck.c +++ b/gcc/c-typeck.c @@ -5254,6 +5254,10 @@ digest_init (tree type, tree init, bool null_pointer_constant, expr.original_type = NULL; maybe_warn_string_init (type, expr); + if (TYPE_DOMAIN (type) && !TYPE_MAX_VALUE (TYPE_DOMAIN (type))) + pedwarn_init (input_location, OPT_pedantic, + "initialization of a flexible array member"); + if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init)), TYPE_MAIN_VARIANT (type))) return inside_init; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index a3e266b..9b66c9d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,10 @@ 2009-04-19 Joseph Myers + PR c/37481 + * gcc.dg/c99-flex-array-7.c: New test. + +2009-04-19 Joseph Myers + PR c/19771 * gcc.c-torture/execute/vla-dealloc-1.c: New test. diff --git a/gcc/testsuite/gcc.dg/c99-flex-array-7.c b/gcc/testsuite/gcc.dg/c99-flex-array-7.c new file mode 100644 index 0000000..8966e6c --- /dev/null +++ b/gcc/testsuite/gcc.dg/c99-flex-array-7.c @@ -0,0 +1,17 @@ +/* Initialization of a flexible array member with a string constant + must be diagnosed. PR 37481. */ +/* { dg-do compile } */ +/* { dg-options "-std=iso9899:1999 -pedantic-errors" } */ + +struct s { int a; char b[]; }; + +struct s a = { 0, "" }; /* { dg-error "initialization of a flexible array member" } */ +/* { dg-error "near init" "near init" { target *-*-* } 8 } */ +struct s b = { 0, { 0 } }; /* { dg-error "initialization of a flexible array member" } */ +/* { dg-error "near init" "near init" { target *-*-* } 10 } */ +struct s c = { 0, { } }; /* { dg-error "ISO C forbids empty initializer braces" } */ +struct s d = { .b = "" }; /* { dg-error "initialization of a flexible array member" } */ +/* { dg-error "near init" "near init" { target *-*-* } 13 } */ +struct s e = { .b = { 0 } }; /* { dg-error "initialization of a flexible array member" } */ +/* { dg-error "near init" "near init" { target *-*-* } 15 } */ +struct s f = { .b = { } }; /* { dg-error "ISO C forbids empty initializer braces" } */