[PATCH] D42787: clang-format: do not add extra indent when wrapping last parameter

Francois Ferrand via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 1 02:35:50 PST 2018


Typz created this revision.
Typz added reviewers: krasimir, djasper, klimek.

There should be no extra indent when wrapping only the expression used
as last argument. This is consistent with the behavior when the first
(and only) argument's expression is wrapped.

  foo(a, bbbbbbbbbbbbbbbbbb +
         ccccccccccccccccc);
  foo(bbbbbbbbbbbbbbbbb +
      ccccccccccccccccc);

This does not affect all other cases, where the argument itself is
wrapped:

  foo(a,
      bbbbbbbbbbbbbbbbb +
          ccccccccccccccccc,
      d);
  foo(bbbbbbbbbbbbbbbbb +
          ccccccccccccccccc,
      d);


Repository:
  rC Clang

https://reviews.llvm.org/D42787

Files:
  lib/Format/ContinuationIndenter.cpp
  unittests/Format/FormatTest.cpp


Index: unittests/Format/FormatTest.cpp
===================================================================
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -3998,6 +3998,21 @@
   verifyFormat("aaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +\n"
                "                      aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,\n"
                "                  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);");
+  verifyFormat(
+      "aaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +\n"
+      "                      aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}");
+  verifyFormat(
+      "aaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +\n"
+      "                          aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,\n"
+      "                      b) {}");
+  verifyFormat(
+      "aaaaaaaaaaaaaaaaaaaaa(b, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +\n"
+      "                         aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}");
+  verifyFormat(
+      "aaaaaaaaaaaaaaaaaaaaa(b,\n"
+      "                      aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +\n"
+      "                          aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,\n"
+      "                      c) {}");
 
   // Indent consistently independent of call expression and unary operator.
   verifyFormat("aaaaaaaaaaa(bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb(\n"
Index: lib/Format/ContinuationIndenter.cpp
===================================================================
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -1094,6 +1094,7 @@
   bool SkipFirstExtraIndent =
       (Previous && (Previous->opensScope() ||
                     Previous->isOneOf(tok::semi, tok::kw_return) ||
+                    (Previous->is(tok::comma) && !Newline) ||
                     (Previous->getPrecedence() == prec::Assignment &&
                      Style.AlignOperands) ||
                     Previous->is(TT_ObjCMethodExpr)));


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42787.132344.patch
Type: text/x-patch
Size: 1980 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180201/cc3ebf3b/attachment-0001.bin>


More information about the cfe-commits mailing list