Without the patch UnwrappedLineFormatter::analyzeSolutionSpace just ran out of possible formattings and would put everything just on one line. The problem was that the the line break was forbidden, but putting the conditional colon on the same line is also forbidden.
Details
Diff Detail
Event Timeline
Fun fact, there is one instance of such a case within the clang-format code. I can't remember where (I stumbled upon this in January, and tried to fix it ever since), should that be reformatted with this patch, or with a follow up?
clang/lib/Format/ContinuationIndenter.cpp | ||
---|---|---|
1412–1417 | Someone put that in on purpose, but is that only intended for java script, then we could add the language check. | |
1423 | Or should we limit that to lambdas in a conditional? That would be even messier to detect. |
Perhaps with a follow-up in which we can reformat the entire directory.
clang/lib/Format/ContinuationIndenter.cpp | ||
---|---|---|
333 | Return true if Current is a conditional colon preceded by a lambda r_brace that is followed by a pair of (possibly empty) parentheses. | |
1412–1417 |
It started as a JavaScript-only behavior but was later extended to cover all languages. | |
1423 |
IMO we should, and it might not be too bad if you override NoLineBreak in canBreak() instead. See line 333 above. |
clang/lib/Format/ContinuationIndenter.cpp | ||
---|---|---|
336 | We can delete this line. |
clang/lib/Format/ContinuationIndenter.cpp | ||
---|---|---|
336 | Added an assert, just to be safe. |
Return true if Current is a conditional colon preceded by a lambda r_brace that is followed by a pair of (possibly empty) parentheses.