Bug 210019 - nested designated initializers are not resolved
Summary: nested designated initializers are not resolved
Status: NEW
Alias: None
Product: CDT
Classification: Tools
Component: cdt-parser (show other bugs)
Version: 5.0   Edit
Hardware: PC Windows XP
: P3 normal with 3 votes (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact: Jonah Graham CLA
URL:
Whiteboard:
Keywords:
: 530289 (view as bug list)
Depends on:
Blocks:
 
Reported: 2007-11-15 15:50 EST by Mike Kucera CLA
Modified: 2020-09-04 15:24 EDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mike Kucera CLA 2007-11-15 15:50:01 EST
Nested designated initializers are not getting resolved. Here is an example:


#include <stdio.h>

typedef struct {
    int x;
    int y;
} Point ;

typedef struct {
    Point p1;
    Point p2;
} Line ;

int main() {
    Point p1 = {.x = 1, .y = 2}; // works fine

    // x and y not resolved
    Line l1  = {{.x = 1, .y = 2}, {.x = 3, .y = 4}}; 

    // x and y not resolved
    Line l2 = {.p1.x = 1, .p1.y = 2, .p2.x = 3, .p2.y = 4};
}


This looks very tricky because the position of the nested initializer within the outer initializer is significant.

I'm trying to get this to work with the new C99 parser and I noticed it doesn't work with the DOM C parser either.
Comment 1 Doug Schaefer CLA 2007-11-15 16:39:10 EST
Wow, good catch Mike. I didn't even know about this feature. I saw some code like it but I thought the guy was just writing pseudo code. You learn something every day...
Comment 2 Mike Kucera CLA 2007-11-15 16:48:51 EST
(In reply to comment #1)

And it looks like it would be pretty hard to implement. Here's an article with some crazy examples (about half way down):

http://www.ddj.com/cpp/184401377

Comment 3 Mike Kucera CLA 2007-11-19 11:10:07 EST
Added test cases:

Failing:
AST2Tests._testBug210019_nestedDesignatedInitializers()

This one passes:
AST2Tests.testBug210019_designatedInitializers()
Comment 4 Nathan Ridge CLA 2018-01-25 17:12:59 EST
*** Bug 530289 has been marked as a duplicate of this bug. ***
Comment 5 Nathan Ridge CLA 2018-01-25 17:14:29 EST
This is still an issue.

In C code, CDT does not produce semantic errors for nested initializers, but they do not get syntax coloring, either.

In C++ code (where GCC supports designated initializers as an extension, and CDT attempts to as well since bug 406462), CDT produces semantic errors for the nested initializers.
Comment 6 Jiri Engelthaler CLA 2018-05-09 02:20:54 EDT
Any progress on this issue?
Comment 7 Nathan Ridge CLA 2018-05-09 02:54:12 EDT
(In reply to Jiri Engelthaler from comment #6)
> Any progress on this issue?

Nope. Given how behind we are on standard C++ support, non-standard extensions like this are a low priority.

If this particular extension is important to you, patches are welcome. I'm happy to help by reviewing.