This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] Allow all but the first string literal in a sequence to be put on a newline
AbandonedPublic

Authored by krasimir on Mar 1 2017, 3:36 AM.

Details

Reviewers
djasper
Summary

This makes clang-format to consider putting all but first string literals from a sequence on a newline, even if they are in the scope of a chain of a binary operator.
This is needed implicitly, since the string literal breaker may break long string literals into multiple lines, and this patch fixes clang-format to remain idempotent in these cases.

source:

long_long_long_long
    << long_long_long_long << "long lo"
                              "ng"

format before (with 40 columns):

long_long_long_long
    << long_long_long_long
    << "long lo"
       "ng"

format after: same as source.

Event Timeline

krasimir created this revision.Mar 1 2017, 3:36 AM
krasimir updated this revision to Diff 90153.Mar 1 2017, 3:42 AM
  • Added a test for a sequence of three string literals
krasimir retitled this revision from [clang-format] Allow the second string literal in a sequence of two to be put on a newline to [clang-format] Allow all but the first string literal in a sequence to be put on a newline.Mar 1 2017, 3:47 AM
krasimir edited the summary of this revision. (Show Details)
krasimir added a reviewer: djasper.
krasimir added a subscriber: cfe-commits.
krasimir updated this revision to Diff 90309.Mar 2 2017, 3:40 AM
  • Add missing test cases for commas and handling for Objective-C string literals
krasimir updated this revision to Diff 90310.Mar 2 2017, 3:42 AM
  • Remove DEBUG statement
krasimir updated this revision to Diff 90312.Mar 2 2017, 3:46 AM
  • Reformat newly added chunk of code
djasper edited edge metadata.Mar 2 2017, 4:31 AM

As discussed offline, I think this solves the wrong problem. My guess is that breakProtrudingToken checks State.Stack.back().NoLinebreak, but I forget to make it also check NoLinebreakInOperand.

krasimir abandoned this revision.Mar 3 2017, 7:32 AM

This patch is superseded by D30575.