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
This commit is contained in:
parent
299b87f8a2
commit
6ccb2a4a4b
6 changed files with 47 additions and 5 deletions
|
@ -1,3 +1,11 @@
|
|||
2009-04-01 Joseph Myers <joseph@codesourcery.com>
|
||||
|
||||
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.
|
||||
|
||||
2009-04-01 Richard Guenther <rguenther@suse.de>
|
||||
|
||||
* fold-const.c (fold_plusminus_mult_expr): Do not fold
|
||||
|
|
12
gcc/c-decl.c
12
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,9 @@
|
|||
2009-04-01 Joseph Myers <joseph@codesourcery.com>
|
||||
|
||||
PR c/39605
|
||||
* gcc.dg/vla-17.c, gcc.dg/vla-18.c: New tests.
|
||||
* gcc.dg/pr25682.c: Update expected diagnostics.
|
||||
|
||||
2009-04-01 Richard Guenther <rguenther@suse.de>
|
||||
|
||||
* gcc.dg/fold-plusmult-2.c: New testcase.
|
||||
|
|
|
@ -10,10 +10,10 @@ struct S
|
|||
int b;
|
||||
};
|
||||
|
||||
char c[(char *) &((struct S *) 0)->b - (char *) 0]; /* { dg-error "variable-size" } */
|
||||
char d[(__SIZE_TYPE__) &((struct S *) 8)->b]; /* { dg-error "variable-size" } */
|
||||
char e[sizeof (c) == __builtin_offsetof (struct S, b) ? 1 : -1]; /* { dg-error "variably modified" } */
|
||||
char f[sizeof (d) == __builtin_offsetof (struct S, b) + 8 ? 1 : -1]; /* { dg-error "variably modified" } */
|
||||
char c[(char *) &((struct S *) 0)->b - (char *) 0]; /* { dg-warning "variably modified" } */
|
||||
char d[(__SIZE_TYPE__) &((struct S *) 8)->b]; /* { dg-warning "variably modified" } */
|
||||
char e[sizeof (c) == __builtin_offsetof (struct S, b) ? 1 : -1];
|
||||
char f[sizeof (d) == __builtin_offsetof (struct S, b) + 8 ? 1 : -1];
|
||||
|
||||
extern void bar (char *, char *);
|
||||
|
||||
|
|
9
gcc/testsuite/gcc.dg/vla-17.c
Normal file
9
gcc/testsuite/gcc.dg/vla-17.c
Normal file
|
@ -0,0 +1,9 @@
|
|||
/* Test diagnostics for VLA whose size folds to an integer constant at
|
||||
file scope. PR 39605. */
|
||||
/* { dg-do compile } */
|
||||
/* { dg-options "" } */
|
||||
|
||||
#define FIRST ((void*)0x80)
|
||||
#define LAST ((void*)0x86)
|
||||
|
||||
static int b[LAST-FIRST]; /* { dg-warning "variably modified 'b' at file scope" } */
|
9
gcc/testsuite/gcc.dg/vla-18.c
Normal file
9
gcc/testsuite/gcc.dg/vla-18.c
Normal file
|
@ -0,0 +1,9 @@
|
|||
/* Test diagnostics for VLA whose size folds to an integer constant at
|
||||
file scope; the diagnostic should be a pedwarn. PR 39605. */
|
||||
/* { dg-do compile } */
|
||||
/* { dg-options "-std=c99 -pedantic-errors" } */
|
||||
|
||||
#define FIRST ((char*)0x80)
|
||||
#define LAST ((char*)0x86)
|
||||
|
||||
static int b[LAST-FIRST]; /* { dg-error "variably modified 'b' at file scope" } */
|
Loading…
Add table
Reference in a new issue