[PATCH] D42376: [clang-format] Ignore UnbreakableTailLength sometimes during breaking

Krasimir Georgiev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 23 02:19:39 PST 2018


krasimir marked an inline comment as done.
krasimir added inline comments.


================
Comment at: lib/Format/ContinuationIndenter.cpp:1579
         (Text.startswith(Prefix = "_T(\"") && Text.endswith(Postfix = "\")"))) {
+      unsigned UnbreakableTailLength = (State.NextToken && canBreak(State))
+                                           ? 0
----------------
djasper wrote:
> I think a comment might help here. Specifically, it should mention that this is required for the special case where there is an unbreakable tail only if certain other formatting decisions have been taken. The UnbreakableTailLength is an overapproximation in that case and we need to be correct here.
> 
> Thinking about this some more, there might actually be cases where this is still not correct as the unbreakable tail is neither 0 nor the precomputed value.
> 
> E.g. can we construct a case where there is a trailing comma in a braced list? Maybe this:
> 
> vector<string> x = {"aaaaaa",};
> 
> In this case, I think the comma will always be part of the string literal, but the "};" only get part of the tail if we don't wrap after the "{".
In the `vector<string> x = {"aaaaa",};` only the comma is part of the `UnbreakableTailLength` of the string:
```
M=1 C=1 T=Unknown S=0 B=0 BK=0 P=59 Name=string_literal L=100 PPK=2 FakeLParens=1/ FakeRParens=0 Text='"aaaaa"'
M=0 C=0 T=Unknown S=0 B=0 BK=0 P=41 Name=comma L=101 PPK=2 FakeLParens= FakeRParens=1 Text=','
M=1 C=1 T=Unknown S=1 B=0 BK=0 P=41 Name=r_brace L=181 PPK=2 FakeLParens= FakeRParens=1 Text='}'
M=0 C=0 T=Unknown S=0 B=0 BK=0 P=23 Name=semi L=182 PPK=2 FakeLParens= FakeRParens=0 Text=';'

breakProtrudingToken: CanBreak=0, UnbreakableTailLength=1
```



Repository:
  rC Clang

https://reviews.llvm.org/D42376





More information about the cfe-commits mailing list