prevent clang-format from breaking string literals

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

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?