diff options
author | Joseph Myers <joseph@codesourcery.com> | 2009-04-01 15:41:06 +0100 |
---|---|---|
committer | Joseph Myers <jsm28@gcc.gnu.org> | 2009-04-01 15:41:06 +0100 |
commit | 6ccb2a4a4bbd43dfbcf9ac56f0f0f7e614874f0c (patch) | |
tree | 1b594cd6ac30f778bcb2ffce2d24267f82199988 /gcc/c-decl.c | |
parent | 299b87f8a21c1ae2611434529c8c4dfc4c291d95 (diff) | |
download | gcc-6ccb2a4a4bbd43dfbcf9ac56f0f0f7e614874f0c.zip gcc-6ccb2a4a4bbd43dfbcf9ac56f0f0f7e614874f0c.tar.gz gcc-6ccb2a4a4bbd43dfbcf9ac56f0f0f7e614874f0c.tar.bz2 |
re PR c/39605 ("error: variable-size type declared outside of any function" is issued twice)
PR c/39605
* c-decl.c (grokdeclarator): Pedwarn for file-scope array
declarator whose size is not an integer constant expression but
folds to an integer constant, then treat it as a constant
subsequently.
testsuite:
* gcc.dg/vla-17.c, gcc.dg/vla-18.c: New tests.
* gcc.dg/pr25682.c: Update expected diagnostics.
From-SVN: r145405
Diffstat (limited to 'gcc/c-decl.c')
-rw-r--r-- | gcc/c-decl.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/gcc/c-decl.c b/gcc/c-decl.c index 3c1c277..9202feb 100644 --- a/gcc/c-decl.c +++ b/gcc/c-decl.c @@ -4408,7 +4408,17 @@ grokdeclarator (const struct c_declarator *declarator, not an integer constant expression. */ if (!size_int_const) { - this_size_varies = size_varies = 1; + /* If this is a file scope declaration of an + ordinary identifier, this is invalid code; + diagnosing it here and not subsequently + treating the type as variable-length avoids + more confusing diagnostics later. */ + if ((decl_context == NORMAL || decl_context == FIELD) + && current_scope == file_scope) + pedwarn (input_location, 0, + "variably modified %qs at file scope", name); + else + this_size_varies = size_varies = 1; warn_variable_length_array (orig_name, size); } } |