Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 314958

Summary: Editor does not format array initializers correctly
Product: [Tools] CDT Reporter: Ladar Levison <ladar>
Component: cdt-editorAssignee: Anton Leherbauer <aleherb+eclipse>
Status: RESOLVED FIXED QA Contact: Anton Leherbauer <aleherb+eclipse>
Severity: normal    
Priority: P3 CC: yevshif
Version: 7.0   
Target Milestone: 7.0.1   
Hardware: All   
OS: All   
Whiteboard:

Description Ladar Levison CLA 2010-05-28 16:34:31 EDT
Build Identifier: 20100520-1308 / CDT 7.0.0.201005241228

With array initializers, the formatting rules are not applied reliably to sub-structure initializers. For example:

typedef struct {
  int a;
  int b;
} CHILD_T;

typedef struct {
  int a;
  CHILD_T b;
} PARENT_T;

PARENT_T sample = {
  .a = 1,
  .b = {
    .a = 1,
    .b = 2,
  }
};

If you start out with the above format, you can get it to stay that way. But if the .b initializer is already on one line, it will stay that way even if the format rules dictate a new line should be inserted. For example:

PARENT_T sample = { .a = 1, .b = { .a = 1,.b = 2 }};

turns into 

PARENT_T sample =
	{
		.a = 1,
		.b = {.a = 1,.b = 2}
	};
	
Also, in a related note the formatter does not insert spaces after the curly braces, even though I have configured it to do so. And in a third, but related note:

PARENT_T sample =
	{
		.a = 1,
		.b = {.a = 1,.b = 2},

		.b = {.a = 1,.b = 2}
	};

There is no way to have the formatter automatically remove that extra blank line between the initializers. I can set number_of_empty_lines_to_preserve to zero, but that will remove all blank lines, not just the ones inserted randomly into initializers.

Reproducible: Always

Steps to Reproduce:
1. Source -> Format
Comment 1 Anton Leherbauer CLA 2010-08-13 06:56:08 EDT
Fixed in HEAD and cdt_7_0.