[PATCH] D95168: [clang-format] Add Insert/Remove Braces option

Björn Schäpers via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Nov 13 11:33:34 PST 2021


HazardyKnusperkeks added a comment.

Should I copy my comments on the old file?



================
Comment at: clang/lib/Format/BraceInserter.cpp:21-56
+bool SupportsAnyAutomaticBraces(FormatStyle &Style, bool insertion) {
+  if (insertion) {
+    if (Style.AutomaticBraces.AfterIf == FormatStyle::BIS_Always)
+      return true;
+    if (Style.AutomaticBraces.AfterIf == FormatStyle::BIS_WrapLikely)
+      return true;
+    if (Style.AutomaticBraces.AfterFor == FormatStyle::BIS_Always)
----------------
MyDeveloperDay wrote:
> HazardyKnusperkeks wrote:
> > How about something like that?
> I think for now
> 
> ```
> bool SupportsAnyAutomaticBraces(FormatStyle &Style, bool insertion) {
>   if (   Style.AutomaticBraces.AfterIf == FormatStyle::BIS_Leave
>       && Style.AutomaticBraces.AfterFor == FormatStyle::BIS_Leave
>       && Style.AutomaticBraces.AfterWhile == FormatStyle::BIS_Leave
>       && Style.AutomaticBraces.AfterDo == FormatStyle::BIS_Leave
>       && Style.AutomaticBraces.AfterElse == FormatStyle::BIS_Leave)
>       return false;
> 
>   if (!insertion){
>     if (Style.AutomaticBraces.AfterIf != FormatStyle::BIS_Remove)
>     && Style.AutomaticBraces.AfterFor != FormatStyle::BIS_Remove)
>     && Style.AutomaticBraces.AfterWhile != FormatStyle::BIS_Remove)
>     && Style.AutomaticBraces.AfterDo != FormatStyle::BIS_Remove)
>     && Style.AutomaticBraces.AfterElse != FormatStyle::BIS_Remove)
>       return false;
>   }
>   return true;
> }
> ```
> 
> Should cover it.
Yeah, but I like my variant better. :)


================
Comment at: clang/lib/Format/Format.cpp:2461
 
-  if (Style.SortIncludes == FormatStyle::SI_CaseInsensitive) {
+  if (Style.SortIncludes == FormatStyle::SI_CaseInsensitive)
     llvm::stable_sort(Indices, [&](unsigned LHSI, unsigned RHSI) {
----------------
I think this should keep its brace.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95168/new/

https://reviews.llvm.org/D95168



More information about the cfe-commits mailing list