[PATCH] D80950: [clang-format] [PR44542,38872] String << String always get a forced newline.

Krasimir Georgiev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 4 02:40:29 PDT 2020


krasimir added a comment.

Another //weak// argument about why the current rule makes sense (break before `<<` between two string literals) is: suppose you don't want such a break. Then you can //change your code// to concatenate the two string literals into a single one, avoiding the problem altogether, if possible (this can be unacceptable in cases where the combined length of the two string literals is excessive, but at that point we will likely break because of the column limit; or when there is a chain of more than 2 string literals and the user wishes to keep them //fluently reflowing// as the code evolves.)

However, a similar argument applies in reverse: suppose clang-format did not force-break before `<<` between two string literals. Then you can force a line break by //adding an empty line comment//. That seems to me like an OK tradeoff between regularity, consistency with non-string literals cases, and flexibility to influence the formatting in cases that are better off with line breaks.

Maybe this at its core is more of a communication/documentation issue, as I can totally see how confusing this heuristic is for users of clang-format.

I'm very slightly against adding a style option for this -- it feels too niche (how will we name it?) and it will leave users with a choice between suboptimal (in my opinion) cases. However adding an option seems like the best tradeoff short of coming up with a good heuristic.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80950





More information about the cfe-commits mailing list