Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 314958 - Editor does not format array initializers correctly
Summary: Editor does not format array initializers correctly
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-editor (show other bugs)
Version: 7.0   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 7.0.1   Edit
Assignee: Anton Leherbauer CLA
QA Contact: Anton Leherbauer CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-05-28 16:34 EDT by Ladar Levison CLA
Modified: 2010-08-13 07:23 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.