Bug 11943 - Accepts invalid declaration "int x[2, 3];" in C99 mode
Summary: Accepts invalid declaration "int x[2, 3];" in C99 mode
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 3.3.1
: P2 normal
Target Milestone: 3.4.0
Assignee: Not yet assigned to anyone
URL:
Keywords: accepts-invalid
Depends on:
Blocks:
 
Reported: 2003-08-16 08:25 UTC by Falk Hueffner
Modified: 2003-10-24 16:11 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2003-08-16 13:19:31


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Falk Hueffner 2003-08-16 08:25:17 UTC
In C99, the brackets must contain an assignment-expression, however, "2, 3" is
not an assignment-expression. I don't have the C89 standard, but I guess it's
similar.

It would be nice to reject this code, because it's a totally useless language
extension, and it might confuse newbies trying to declare two-dimensional arrays.
Comment 1 Debian GCC Maintainers 2003-08-16 09:04:32 UTC
[forwarded from http://bugs.debian.org/177303]
Comment 2 Andrew Pinski 2003-08-16 13:19:31 UTC
I can confirm this on the mainline (20030815).
The problem is that in the c-parse.y (really c-parse.in)
The array_declarator is defined as follows:
array_declarator:
        '[' maybe_type_quals_attrs expr ']'
                { $$ = build_array_declarator ($3, $2, 0, 0); }
        | '[' maybe_type_quals_attrs ']'
                { $$ = build_array_declarator (NULL_TREE, $2, 0, 0); }
        | '[' maybe_type_quals_attrs '*' ']'
                { $$ = build_array_declarator (NULL_TREE, $2, 0, 1); }
        | '[' STATIC maybe_type_quals_attrs expr ']'
                { $$ = build_array_declarator ($4, $3, 1, 0); }
        /* declspecs_nosc_nots is a synonym for type_quals_attrs.  */
        | '[' declspecs_nosc_nots STATIC expr ']'
                { $$ = build_array_declarator ($4, $2, 1, 0); }
        ;
which is different from what C99 says.
Comment 3 GCC Commits 2003-10-24 15:30:45 UTC
Subject: Bug 11943

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	jsm28@gcc.gnu.org	2003-10-24 15:30:37

Modified files:
	gcc            : ChangeLog c-parse.in 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gcc.dg: c99-arraydecl-2.c 

Log message:
	* c-parse.in (array_declarator): Use expr_no_commas.
	Fixes PR c/11943.
	
	testsuite:
	* gcc.dg/c99-arraydecl-2.c: New test.  PR c/11943.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.1542&r2=2.1543
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-parse.in.diff?cvsroot=gcc&r1=1.187&r2=1.188
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.3143&r2=1.3144
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/c99-arraydecl-2.c.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 4 Andrew Pinski 2003-10-24 16:11:08 UTC
Fixed for 3.4.