diff options
author | jsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-09-28 19:35:26 +0000 |
---|---|---|
committer | jsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-09-28 19:35:26 +0000 |
commit | 5cbd179d875444116e92838078534bcf689ccff3 (patch) | |
tree | 5fc1cb98a75ae0a4738fa2fd992b53aee46095a7 /gcc/c-decl.c | |
parent | 0ecedb6fdf659f79d6d35c973874a5c502982ed3 (diff) | |
download | gcc-5cbd179d875444116e92838078534bcf689ccff3.tar.gz |
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.
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
Diffstat (limited to 'gcc/c-decl.c')
-rw-r--r-- | gcc/c-decl.c | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/gcc/c-decl.c b/gcc/c-decl.c index 3a2f5763b13..413787633dc 100644 --- a/gcc/c-decl.c +++ b/gcc/c-decl.c @@ -2986,6 +2986,15 @@ start_decl (struct c_declarator *declarator, struct c_declspecs *declspecs, 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; + } } if (initialized) @@ -3416,9 +3425,14 @@ build_compound_literal (tree type, tree init) /* 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); + tree decl; tree complit; tree stmt; + + 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); |