[PATCH] D114521: [clang-format] [PR47936] AfterControlStatement: MultiLine breaks AllowShortFunctionsOnASingleLine

MyDeveloperDay via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 24 08:23:28 PST 2021


MyDeveloperDay added a comment.



> @curdeius 
> Alright, I'll create a report https://bugs.llvm.org/show_bug.cgi?id=52598

That is related. But I'd rather handle it separately because the fix for the function and the fix for a while or if will need to be different.

It really comes down to this line..

  if (Line.First == Line.Last && Line.First->isNot(TT_FunctionLBrace)

in the if case and in the while case the `{` isn't labeled like it is for the function

  M=0 C=0 T=Unknown S=1 F=0 B=0 BK=1 P=0 Name=l_brace L=1 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='{'

To be honest this is something we should think about, if every `{` and `}` every `(`,`)` and `[`,`]` got given a Type labels this would be super good at disambiguating them

This is not something new, we've been doing it with the ')' of a cstyle cast for years `CastRParen`

  M=0 C=0 T=Unknown S=1 F=0 B=0 BK=0 P=0 Name=int L=3 PPK=2 FakeLParens=2/ FakeRParens=0 II=0x25a969b1660 Text='int'
  M=0 C=1 T=StartOfName S=1 F=0 B=0 BK=0 P=220 Name=identifier L=5 PPK=2 FakeLParens= FakeRParens=0 II=0x25a969b8768 Text='a'
  M=0 C=0 T=BinaryOperator S=1 F=0 B=0 BK=0 P=22 Name=equal L=7 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='='
  M=0 C=1 T=Unknown S=1 F=0 B=0 BK=0 P=22 Name=l_paren L=9 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='('
  M=0 C=0 T=Unknown S=0 F=0 B=0 BK=0 P=59 Name=int L=12 PPK=2 FakeLParens= FakeRParens=0 II=0x25a969b1660 Text='int'
  M=0 C=0 T=CastRParen S=0 F=0 B=0 BK=0 P=43 Name=r_paren L=13 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text=')'

but in this case, the real problem here is that `Multiline`  just too lax, basically Multiline doesn't in my view seem to be doing what it expects

F20680737: image.png <https://reviews.llvm.org/F20680737>

>From this is seems it should ONLY be returning 0 (meaning don't join the line), if the "clause" in the (if,for,while) contains multiple conditions that have been broken over several lines.

I just don't think this is sufficiently constrained.

  // Don't merge a trailing multi-line control statement block like:
  // } else if (foo &&
  //            bar)
  // { <-- current Line
  //   baz();
  // }
  if (Line.First == Line.Last  &&
      Style.BraceWrapping.AfterControlStatement ==
          FormatStyle::BWACS_MultiLine)
    return 0;




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114521



More information about the cfe-commits mailing list