This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] Break before next parameter after a formatted multiline raw string parameter
ClosedPublic

Authored by krasimir on Sep 24 2018, 7:18 PM.

Details

Summary

Currently clang-format breaks before the next parameter after multiline parameters (also recursively for the parent expressions of multiline parameters). However, it fails to do so for formatted multiline raw string literals:

$ cat test.cc
// Examples

// Regular multiline tokens
int x = f(R"(multi
             line)", 2);
}

int y = g(h(R"(multi
              line)"), 2);

// Formatted multiline tokens
int z = f(R"pb(multi: 1  #
               line: 2)pb", 2);

int w = g(h(R"pb(multi: 1  #
                 line: 2)pb"), 2);
$ clang-format -style=google test.cc
// Examples

// Regular multiline tokens
int x = f(R"(multi
             line)",
          2);
}

int y = g(h(R"(multi
              line)"),
          2);

// Formatted multiline tokens
int z = f(R"pb(multi: 1  #
               line: 2)pb", 2);

int w = g(h(R"pb(multi: 1  #
                 line: 2)pb"), 2);

This patch addresses this inconsistency by forcing breaking after multiline formatted raw string literals. This requires a little tweak to the indentation chosen for the contents of a formatted raw string literal: in case when that's a parameter and not the last one, the indentation is based off of the uniform indentation of all of the parameters.

Diff Detail

Event Timeline

krasimir created this revision.Sep 24 2018, 7:18 PM
krasimir edited the summary of this revision. (Show Details)Oct 1 2018, 8:29 AM
krasimir edited the summary of this revision. (Show Details)Oct 1 2018, 8:42 AM
krasimir updated this revision to Diff 167749.Oct 1 2018, 9:11 AM
  • Add more tests and tidy-up
sammccall accepted this revision.Oct 24 2018, 2:43 AM
sammccall added inline comments.
lib/Format/ContinuationIndenter.cpp
1594

nit: why are you doing the multiline side-effect between computing the penalty and returning it?

This revision is now accepted and ready to land.Oct 24 2018, 2:43 AM
krasimir marked an inline comment as done.Oct 25 2018, 12:39 AM
krasimir added inline comments.
lib/Format/ContinuationIndenter.cpp
1594

Thank you!

krasimir updated this revision to Diff 171041.Oct 25 2018, 12:39 AM
krasimir marked an inline comment as done.
  • Address review comment
This revision was automatically updated to reflect the committed changes.