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]; }
(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.
Confirmed.
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
Fixed.