[cfe-dev] prevent clang-format from breaking string literals

Daniel Jasper djasper at google.com
Wed Jun 24 01:09:43 PDT 2015


Yes, this is something that clang-format currently cannot do. It would take
a bit longer to explain why this is architecturally difficult (based on the
penalties).

However, we have already disabled string breaking for Java and JavaScript
(see
http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20141208/119958.html).
This could be turned into a configuration option. Would you be willing to
contribute a patch?

On Fri, Apr 17, 2015 at 9:24 AM, Neumann, Adrian <adrian.neumann at siemens.com
> wrote:

> Hi,
>
> I would like to configure clang-format (version 3.6.0) not to break long
> string literals despite the ColumnLimit. I tried setting PenaltyBreakString
> to a large value and PenaltyExcessCharacter to a small value. This doesn't
> seem to have any effect.
>
> This is an example program:
>
> #include <string>
>
> int main() {
>         std::string s = "this is a really long string that"
>                 "i really would like to have formatted differently, in
> particular I want this line to stay like this";
> }
>
> clang-format --dump-config reports
>
> ColumnLimit:     80
> PenaltyBreakBeforeFirstCallParameter: 19
> PenaltyBreakComment: 300
> PenaltyBreakString: 2000000
> PenaltyBreakFirstLessLess: 120
> PenaltyExcessCharacter: 1
> PenaltyReturnTypeOnItsOwnLine: 60
>
> yet the program is formatted as such:
>
> #include <string>
>
> int main() {
>   std::string s = "this is a really long string that"
>                   "i really would like to have formatted differently, in "
>                   "particular I want this line to stay like this";
> }
>
> I there a way to solve this problem, or is this something clang can't do?
>
> Greets,
>
> Adrian
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150624/15ee3377/attachment.html>


More information about the cfe-dev mailing list