* 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.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@145405
138bc75d-0d04-0410-961f-
82ee72b054a4
+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
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);
}
}
+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.
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 *);
--- /dev/null
+/* 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" } */
--- /dev/null
+/* 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" } */