* c-decl.c (start_decl): Check for initializing incomplete array
of VLAs.
(build_compound_literal): Check for TYPE being error_mark_node.
* c-parse.in (primary): Check for VLA compound literals.
testsuite:
* gcc.dg/vla-init-2.c, gcc.dg/vla-init-3.c, gcc.dg/vla-init-4.c,
gcc.dg/vla-init-5.c: New tests.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@88248
138bc75d-0d04-0410-961f-
82ee72b054a4
+2004-09-28 Joseph S. Myers <jsm@polyomino.org.uk>
+
+ PR c/16409
+ * c-decl.c (start_decl): Check for initializing incomplete array
+ of VLAs.
+ (build_compound_literal): Check for TYPE being error_mark_node.
+ * c-parse.in (primary): Check for VLA compound literals.
+
2004-09-28 Diego Novillo <dnovillo@redhat.com>
* tree-ssa-live.c (calculate_live_on_entry): Fix warnings
2004-09-28 Diego Novillo <dnovillo@redhat.com>
* tree-ssa-live.c (calculate_live_on_entry): Fix warnings
error ("elements of array %qD have incomplete type", decl);
initialized = 0;
}
error ("elements of array %qD have incomplete type", decl);
initialized = 0;
}
+ else if (C_DECL_VARIABLE_SIZE (decl))
+ {
+ /* Although C99 is unclear about whether incomplete arrays
+ of VLAs themselves count as VLAs, it does not make
+ sense to permit them to be initialized given that
+ ordinary VLAs may not be initialized. */
+ error ("variable-sized object may not be initialized");
+ initialized = 0;
+ }
/* We do not use start_decl here because we have a type, not a declarator;
and do not use finish_decl because the decl should be stored inside
the COMPOUND_LITERAL_EXPR rather than added elsewhere as a DECL_EXPR. */
/* We do not use start_decl here because we have a type, not a declarator;
and do not use finish_decl because the decl should be stored inside
the COMPOUND_LITERAL_EXPR rather than added elsewhere as a DECL_EXPR. */
- tree decl = build_decl (VAR_DECL, NULL_TREE, type);
+
+ if (type == error_mark_node)
+ return error_mark_node;
+
+ decl = build_decl (VAR_DECL, NULL_TREE, type);
DECL_EXTERNAL (decl) = 0;
TREE_PUBLIC (decl) = 0;
TREE_STATIC (decl) = (current_scope == file_scope);
DECL_EXTERNAL (decl) = 0;
TREE_PUBLIC (decl) = 0;
TREE_STATIC (decl) = (current_scope == file_scope);
| '(' typename ')' '{'
{ start_init (NULL_TREE, NULL, 0);
$<ttype>$ = groktypename ($2);
| '(' typename ')' '{'
{ start_init (NULL_TREE, NULL, 0);
$<ttype>$ = groktypename ($2);
+ if (C_TYPE_VARIABLE_SIZE ($<ttype>$))
+ {
+ error ("compound literal has variable size");
+ $<ttype>$ = error_mark_node;
+ }
really_start_incremental_init ($<ttype>$); }
initlist_maybe_comma '}' %prec UNARY
{ struct c_expr init = pop_init_level (0);
really_start_incremental_init ($<ttype>$); }
initlist_maybe_comma '}' %prec UNARY
{ struct c_expr init = pop_init_level (0);
+2004-09-28 Joseph S. Myers <jsm@polyomino.org.uk>
+
+ PR c/16409
+ * gcc.dg/vla-init-2.c, gcc.dg/vla-init-3.c, gcc.dg/vla-init-4.c,
+ gcc.dg/vla-init-5.c: New tests.
+
2004-09-27 Joseph S. Myers <jsm@polyomino.org.uk>
PR c/13804
2004-09-27 Joseph S. Myers <jsm@polyomino.org.uk>
PR c/13804
--- /dev/null
+/* Arrays of unknown size with element type a VLA type should not be
+ initialized (C99 isn't clear about whether such arrays are VLAs,
+ but this is the only reasonable interpretation). Bug 16409, first
+ testcase. */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+const int i = 1;
+void foo() { char a[][i] = {""}; } /* { dg-error "error: variable-sized object may not be initialized" } */
+/* { dg-error "array size missing in 'a'" "extra error" { target *-*-* } 9 } */
--- /dev/null
+/* Arrays of unknown size with element type a VLA type should not be
+ initialized (C99 isn't clear about whether such arrays are VLAs,
+ but this is the only reasonable interpretation). Bug 16409, second
+ testcase. */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+void foo(int i) { char a[][i] = {""}; } /* { dg-error "error: variable-sized object may not be initialized" } */
+/* { dg-error "array size missing in 'a'" "extra error" { target *-*-* } 8 } */
--- /dev/null
+/* Test for ICE on VLA compound literal. */
+/* Origin: Joseph Myers <jsm@polyomino.org.uk> */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+const int i = 1;
+void foo() { char *p = (char [i]){ "" }; } /* { dg-error "error: compound literal has variable size" } */
--- /dev/null
+/* Test for ICE on incomplete-array-of-VLA compound literal. */
+/* Origin: Joseph Myers <jsm@polyomino.org.uk> */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+const int i = 1;
+void foo() { void *p = (char [][i]){ "" }; } /* { dg-error "error: compound literal has variable size" } */