Page MenuHomePhabricator

[clang-format] [PR42164] Add Option to Break before While
ClosedPublic

Authored by MyDeveloperDay on May 4 2020, 6:06 AM.

Details

Summary

Its currently not possible to recreate the GNU style using the BreakBeforeBraces: Custom style due to a lack of missing BeforeWhile in the BraceWrappingFlags

The following request was raised to add BeforeWhile in a do..while context like BeforeElse and BeforeCatch to give greater control over the positioning of the while

https://bugs.llvm.org/show_bug.cgi?id=42164

Diff Detail

Event Timeline

MyDeveloperDay created this revision.May 4 2020, 6:06 AM
krasimir marked an inline comment as done.May 6 2020, 11:47 AM
krasimir added inline comments.
clang/lib/Format/Format.cpp
708

Awesome!

clang/lib/Format/UnwrappedLineParser.cpp
2178

Why not remove Style.BraceWrapping.IndentBraces?

  • should be a no-op for GNU style,
  • other styles don't IndentBraces,
  • we can add a sentence in the release notes that previously IndentBraces implied the new "BeforeWhile" option, and now you just have to set it if you're using a custom GNU-like style.
MyDeveloperDay marked 2 inline comments as done.May 7 2020, 12:16 PM
MyDeveloperDay added inline comments.
clang/lib/Format/UnwrappedLineParser.cpp
2178

IndentBraces is used elsewhere inside parseLabel() and CompoundStatementIndenter, I think I'd be uncomfortable about removing it.

There are 1000's of references to it in GitHub.

https://github.com/search?l=YAML&q=%22IndentBraces%3A+true%22&type=Code

https://github.com/search?q=%22IndentBraces%3A+false%22&type=Code

krasimir added inline comments.May 12 2020, 1:59 PM
clang/lib/Format/UnwrappedLineParser.cpp
2178

I'm sorry, I wasn't clear: why not remove Style.BraceWrapping.IndentBraces || from line 2170, leaving the value of the new option Style.BraceWrapping.BeforeWhile be the only thing that determines whether a newline is added before the while in a do-while block?

krasimir requested changes to this revision.May 15 2020, 4:02 AM
This revision now requires changes to proceed.May 15 2020, 4:02 AM
MyDeveloperDay planned changes to this revision.May 15 2020, 4:39 AM
MyDeveloperDay marked an inline comment as done.

let me try that..

Use BeforeWhile and not IndentBraces to wrap the line
Update the release notes

krasimir accepted this revision.May 18 2020, 1:21 AM

Thank you!

This revision is now accepted and ready to land.May 18 2020, 1:21 AM
This revision was automatically updated to reflect the committed changes.