Bug 22192 - Rejection of valid array declaration.
Summary: Rejection of valid array declaration.
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.1.0
: P3 minor
Target Milestone: 4.1.0
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
Depends on:
Blocks: 16989
  Show dependency treegraph
 
Reported: 2005-06-26 15:10 UTC by Neil Booth
Modified: 2005-07-29 05:39 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-06-27 13:49:19


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Neil Booth 2005-06-26 15:10:49 UTC
With -fsyntax-only GCC erroneously rejects the following array 'x' as having
non-constant size.  Its size should evaluate to 1.

int
bar (int v)
{
  int (*p)[v];
  int (*q)[2];

  static int x[sizeof(*(v ? p : q)) == 2 * sizeof (int)];

  return x[0];
}
Comment 1 Neil Booth 2005-06-26 15:11:36 UTC
(In reply to comment #0)
> With -fsyntax-only GCC erroneously rejects the following array 'x' as having
> non-constant size.  Its size should evaluate to 1.
> 
> int
> bar (int v)
> {
>   int (*p)[v];
>   int (*q)[2];
> 
>   static int x[sizeof(*(v ? p : q)) == 2 * sizeof (int)];
> 
>   return x[0];
> }

I should add that switching p and q causes GCC to accept it.
Comment 2 Andrew Pinski 2005-06-27 13:49:19 UTC
Confirmed.
Comment 3 GCC Commits 2005-07-29 02:42:47 UTC
Subject: Bug 22192

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	jsm28@gcc.gnu.org	2005-07-29 02:42:20

Modified files:
	gcc            : ChangeLog c-typeck.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gcc.dg: c99-vla-2.c 

Log message:
	PR c/22192
	* c-typeck.c (composite_type): Prefer constant size arrays to
	VLAs.
	
	testsuite:
	* gcc.dg/c99-vla-2.c: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.9594&r2=2.9595
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-typeck.c.diff?cvsroot=gcc&r1=1.470&r2=1.471
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.5848&r2=1.5849
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/c99-vla-2.c.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 4 Andrew Pinski 2005-07-29 05:39:33 UTC
Fixed.