Page MenuHomePhabricator

[clang-format] Add BeforeWhileInDoWhile BraceWrapping option
Needs ReviewPublic

Authored by ebaker355 on Jan 11 2016, 7:35 AM.



Adds a new BraceWrapping option called BeforeWhileInDoWhile.

Code like this:

do {
    // Some code
} while (1);


do {
    // Some code
while (1);

This is meant to compliment the BreakBeforeElse wrapping option.

I couldn't think of a better name for the option than BeforeWhileInDoWhile. I'm open to suggestions!

Also, this is my first attempt at submitting a patch for this project. If I've done anything wrong, please let me know. Thanks!

Diff Detail

Event Timeline

ebaker355 updated this revision to Diff 44505.Jan 11 2016, 7:35 AM
ebaker355 retitled this revision from to Add BeforeWhileInDoWhile BraceWrapping option.
ebaker355 updated this object.
ebaker355 added a subscriber: cfe-commits.
ebaker355 updated this revision to Diff 44506.Jan 11 2016, 7:38 AM

Remove unintended blank line change.

ebaker355 retitled this revision from Add BeforeWhileInDoWhile BraceWrapping option to [clang-format] Add BeforeWhileInDoWhile BraceWrapping option.Jan 11 2016, 7:41 AM
ebaker355 updated this object.Jan 14 2016, 9:24 AM
ebaker355 added a reviewer: djasper.

Ping. Anyone have an opinion on this?

djasper edited edge metadata.Jan 26 2016, 4:40 AM

Is there a coding style that actually recommends this? I would be quite doubtful that it is a good idea as it makes those loops harder to distinguish from other while loops. Generally, there is a certain bar to getting additional style flags into clang-format:

Thanks for responding, and for the documentation link! It is certainly wise to not attempt "to supporting every single style used by a codebase somewhere in the wild."

I do not know of a predefined coding style that recommends this format. My thinking was:

  • it complements the "else on new line" option
  • I have seen other code formatters that offer this style option
ebaker355 abandoned this revision.Jan 26 2016, 6:25 AM

Since I cannot meet these criteria:

  • be used in a project of significant size (have dozens of contributors)
  • have a publicly accessible style guide

I will abandon this revision request. Thank you for considering!

Feel free to leave this patch around. Maybe somebody else comes up with something that meets the other criteria ;-).

Me personally, I just think that seeing "while (1);" on a single line is quite misleading. But maybe that is just me.

ebaker355 reclaimed this revision.EditedJan 26 2016, 6:40 AM

Ok, cool! :) Thanks!

Yeah, personally, I like seeing the vertical alignment of the keywords, especially in code editors that draw indentation lines.

MyDeveloperDay added a project: Restricted Project.Oct 11 2019, 2:48 AM
MyDeveloperDay added a subscriber: MyDeveloperDay.

This change need unit tests