This new option InsertBraces has been tested on make clang and make check-clang. It has almost zero overhead when turned off.
- Why this new patch?
Because of this comment, I ran
https://reviews.llvm.org/D95168?id=322240 (the last diff before @MyDeveloperDay took over) on make clang and indeed it failed a lot.
- Why isn't this option an enum or a struct?
We plan to re-configure/re-package RemoveBracesLLVM to support other styles. After that, one can simply turn on InsertBraces and specify the suboptions of RemoveBraces.
- How does InsertBraces work with RemoveBracesLLVM (or the future RemoveBraces after the latter is renamed and expanded)?
Simply turn on both options (or the desired suboptions of RemoveBraces when it becomes available). See the example below:
$ cat f.cpp if (a) { f(); } else // comment while (b) --b; $ clang-format -style="{RemoveBracesLLVM: true}" f.cpp # Incorrect. if (a) f(); else // comment while (b) --b; $ clang-format -style="{InsertBraces: true, RemoveBracesLLVM: true}" f.cpp if (a) { f(); } else { // comment while (b) --b; } $
Please add a comment in which cases the braces are added. If I understand correctly, everywhere except for PP directives, right?