Bug 39581 - VLA types at file scope wrongly rejected
Summary: VLA types at file scope wrongly rejected
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.5.0
: P3 normal
Target Milestone: 4.5.0
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
Depends on:
Blocks: 16989
  Show dependency treegraph
 
Reported: 2009-03-29 20:01 UTC by Joseph S. Myers
Modified: 2009-04-26 17:01 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work: 4.5.0
Known to fail:
Last reconfirmed: 2009-03-30 01:10:24


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Joseph S. Myers 2009-03-29 20:01:32 UTC
GCC gives an error "variable-size type declared outside of any function"
for code such as:

int a;
int b = sizeof (int (*)[a]);

As far as I can tell there is no basis for this in C99; the sizeof expression
certainly has result an integer constant in this case and its operand
is not evaluated.  It's declarations of ordinary identifiers with variably
modified type that aren't allowed outside functions.

Similarly, casts to variably modified types should be permitted at file
scope under similar circumstances to those accepted in static initializers
in gcc.dg/c99-const-expr-11.c (and gnu99-const-expr-3.c).
Comment 1 Joseph S. Myers 2009-04-26 17:00:36 UTC
Subject: Bug 39581

Author: jsm28
Date: Sun Apr 26 17:00:04 2009
New Revision: 146806

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=146806
Log:
	PR c/39581
	* c-decl.c (global_bindings_p): Return negative value.
	(c_variable_size): New.  Based on variable_size from
	stor-layout.c.
	(grokdeclarator): Call c_variable_size not variable_size.

testsuite:
	* gcc.dg/c99-const-expr-14.c, gcc.dg/gnu99-const-expr-4.c,
	gcc.dg/vla-21.c: New tests.

Added:
    trunk/gcc/testsuite/gcc.dg/c99-const-expr-14.c
    trunk/gcc/testsuite/gcc.dg/gnu99-const-expr-4.c
    trunk/gcc/testsuite/gcc.dg/vla-21.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/c-decl.c
    trunk/gcc/testsuite/ChangeLog

Comment 2 Joseph S. Myers 2009-04-26 17:01:17 UTC
Fixed for 4.5.