Bug 40864 - Designated initializers for multi-dimensional arrays fail in Objective-C
Summary: Designated initializers for multi-dimensional arrays fail in Objective-C
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: objc (show other bugs)
Version: 4.2.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: FIXME, rejects-valid
Depends on:
Blocks:
 
Reported: 2009-07-26 21:15 UTC by Sergei Yakovlev
Modified: 2021-11-12 09:55 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2017-07-27 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sergei Yakovlev 2009-07-26 21:15:16 UTC
Designated initializers for multi-dimensional arrays work great in C (C99), but fail in Objective-C (see example below). Given that Objective-C is proclaimed a strict superset of C, I consider this a bug.

$ gcc -x c - <<<"int main(){ int a[3][4] = {[1][2] = 5}; }"
$ gcc -x objective-c - <<<"int main(){ int a[3][4] = {[1][2] = 5}; }"
<stdin>: In function 'main':
<stdin>:1: error: syntax error before ']' token
$
Comment 1 jsm-csl@polyomino.org.uk 2009-07-26 21:43:53 UTC
Subject: Re:   New: Designated initializers for multi-dimensional
 arrays fail in Objective-C

On Sun, 26 Jul 2009, sergei dot yakovlev at gmail dot com wrote:

> Designated initializers for multi-dimensional arrays work great in C (C99), but
> fail in Objective-C (see example below). Given that Objective-C is proclaimed a
> strict superset of C, I consider this a bug.

This was a property of the old C parser I carefully replicated when 
writing the new one.  I do not know if there exists a C99-based 
specification of ObjC that clarifies what is intended (and note that this 
interacts with the old GNU form of designated initializers as well); I 
took it as given by the implementation at that time.

              /* ??? Following the old parser, [ objc-receiver
                 objc-message-args ] is accepted as an initializer,
                 being distinguished from a designator by what follows
                 the first assignment expression inside the square
                 brackets, but after a first array designator a
                 subsequent square bracket is for Objective-C taken to
                 start an expression, using the obsolete form of
                 designated initializer without '=', rather than
                 possibly being a second level of designation: in LALR
                 terms, the '[' is shifted rather than reducing
                 designator to designator-list.  */

Comment 2 Sergei Yakovlev 2009-12-29 22:22:57 UTC
@fxcoudert: This is not an enhancement, this is a bug. Objective-C is declared as a strict superset of C. Everything that works in C should work in Objective-C. In this case, it doesn't, which means it's a bug.
Comment 3 Eric Gallager 2017-07-27 16:36:44 UTC
Confirmed.
Comment 4 Eric Gallager 2019-07-26 21:32:15 UTC
cc-ing objc maintainers