bugGNU indent - Bugs: bug #42355, option to insert braces for...

 
 

bug #42355: option to insert braces for single-statements for conditionals

Submitter:  None
Submitted:  Wed 14 May 2014 12:52:05 PM UTC
   
 
Category:  C Severity:  3 - Normal
Item Group:  Wishlist Status:  None
Privacy:  Public Assigned to:  None
Open/Closed:  Open
* Mandatory Fields

Add a New Comment Rich Markup
   

Wed 14 May 2014 12:52:05 PM UTC, original submission:  

(aka "One True Brace Style", OTBS, 1TBS, a stricter variant of K&R)

That is, to convert

if (a) foo();
if (b) bar(); else baz();
while (c) zap();
do re() while (mi);
for (...) blah();

into

if (a) {
  foo();
}
if (b) {
  bar();
} else {
  baz();
}
while (c) {
 zap();
}
do {
  re();
} while (mi);
for (...) {
  blah();
}

Handling of comments is a bit tricky, I guess the idea would be to insert the braces between the conditional and any possibly trailing comment:

if (a) /* foo */
  /* bar */
  foo(); /* baz */

would become

if (a) { /* foo */
  /* bar */
  foo();  /* baz */
}

I think there could be conversely an option to remove such braces, to turn

if (a) {
 foo();
}

but that would be anti-1TBS...

into

if (a)
  foo;

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

CC list is empty

 

There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

Only logged-in users can vote.

 

No changes have been made to this item

Back to the top

Powered by Savane 3.13-758e.
Corresponding source code