Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 369068 - [formatter] C99 compound literals break formatting
Summary: [formatter] C99 compound literals break formatting
Status: CLOSED WORKSFORME
Alias: None
Product: CDT
Classification: Tools
Component: cdt-core (show other bugs)
Version: 8.0   Edit
Hardware: PC All
: P3 normal with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact: Markus Schorn CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-01-19 07:50 EST by Missing name CLA
Modified: 2019-05-26 05:45 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Missing name CLA 2012-01-19 07:50:16 EST
Build Identifier: 20110916-0149

Formatting of compound literals looks ugly in *.c, *.cpp, *.h files.
In *.c files it can even break formatting for parent if/while/do/for/switch construction.

Compound literal example: (foo_t) { 0, { 'a', 'b'} };

In *.cpp and *.h files formatting is still incorrect but it at least does not ruin conditional/loop statements.



Reproducible: Always

Steps to Reproduce:
1. In C or C++ project in *.c file paste following code:
int main()
{
	struct foo
	{
		int a;
		char b[2];
	};

	if (1)
	{
		foo structure;
		structure = (struct foo) { 0, { 'a', 'b'} };
	}
}
2. Autoformat it (using hotkey "Format Source Code" Ctrl+Shift+F).
3. Result is:
int main()
{
	struct foo
	{
		int a;
		char b[2];
	};

	if (1)
	{
		foo structure;
		structure = (struct foo)
				{	0,
					{	'a', 'b'}};
			}
		}

Compound literal is broken into multiple lines by formatter. Some tabs are inserted inside the curly brackets. Indentation is broken in 'if'.

Expected result:
formatting '(struct foo) { 0, { 'a', 'b'} }' is just fine. Should leave it as is.
Comment 1 Marco Stornelli CLA 2019-05-26 05:45:57 EDT
I'm not able to reproduce this problem using CDT 9.7. Re-open if you still have this problem using an updated version.