clang-format: Fix AlwaysBreakBeforeMultilineStrings with ColumnLimit=0

Before:
  const char *x =
      "hello llvm";

After:
  const char *x = "hello llvm";

This fixes llvm.org/PR22245.
Patch by Bill Meltsner, thank you!

llvm-svn: 226564
This commit is contained in:
Daniel Jasper 2015-01-20 12:59:20 +00:00
parent fbeb7e65d9
commit 6fd5d646cc
2 changed files with 6 additions and 2 deletions

View File

@ -1081,8 +1081,9 @@ bool ContinuationIndenter::nextIsMultilineString(const LineState &State) {
if (Current.getNextNonComment() &&
Current.getNextNonComment()->isStringLiteral())
return true; // Implicit concatenation.
if (State.Column + Current.ColumnWidth + Current.UnbreakableTailLength >
Style.ColumnLimit)
if (Style.ColumnLimit != 0 &&
State.Column + Current.ColumnWidth + Current.UnbreakableTailLength >
Style.ColumnLimit)
return true; // String will be split.
return false;
}

View File

@ -4611,6 +4611,9 @@ TEST_F(FormatTest, AlwaysBreakBeforeMultilineStrings) {
format("NSString *const kString = @\"aaaa\"\n"
"\"bbbb\";",
Break));
Break.ColumnLimit = 0;
verifyFormat("const char *hello = \"hello llvm\";", Break);
}
TEST_F(FormatTest, AlignsPipes) {