]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c/37481 (-pedantic accepts flexible array member = "string" initialization)
authorJoseph Myers <joseph@codesourcery.com>
Sun, 19 Apr 2009 20:38:53 +0000 (21:38 +0100)
committerJoseph Myers <jsm28@gcc.gnu.org>
Sun, 19 Apr 2009 20:38:53 +0000 (21:38 +0100)
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.

From-SVN: r146359

gcc/ChangeLog
gcc/c-typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/c99-flex-array-7.c [new file with mode: 0644]

index 01488bf8bf9bdb30ad14b5577ffcf8b685205732..6b4517977403944a3f8c0427b0cc563677bc9075 100644 (file)
@@ -1,3 +1,9 @@
+2009-04-19  Joseph Myers  <joseph@codesourcery.com>
+
+       PR c/37481
+       * c-typeck.c (digest_init): Check for initializing an array with a
+       string literal.
+
 2009-04-19  Joseph Myers  <joseph@codesourcery.com>
 
        PR c/19771
index 821f4ce13a6a151649bdbc1ceaf1f331c3a2e175..96b1a5da59920991a0014d86f2bede18007350fd 100644 (file)
@@ -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;
index a3e266be90a7e4ee1b82cd18d4025324dbb349a1..9b66c9dd950bee061aab2c3fd150fe8ad80b49b8 100644 (file)
@@ -1,3 +1,8 @@
+2009-04-19  Joseph Myers  <joseph@codesourcery.com>
+
+       PR c/37481
+       * gcc.dg/c99-flex-array-7.c: New test.
+
 2009-04-19  Joseph Myers  <joseph@codesourcery.com>
 
        PR c/19771
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 (file)
index 0000000..8966e6c
--- /dev/null
@@ -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" } */