krasimir created this revision.
krasimir requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Commit
https://github.com/llvm/llvm-project/commit/f7f9f94b2e2b4c714bac9036f6b73a3df42daaff
changed the indent of ObjC method arguments from +4 to +2, if the method
occurs after a block statement.  I believe this was unintentional and there
was insufficient ObjC test coverage to catch this.

Example: `clang-format -style=google test.mm`

before:

  void aaaaaaaaaaaaaaaaaaaaa(int c) {
    if (c) {
      f();
    }
    [dddddddddddddddddddddddddddddddddddddddddddddddddddddddd
        eeeeeeeeeeeeeeeeeeeeeeeeeeeee:^(fffffffffffffff gggggggg) {
          f(SSSSS, c);
        }];
  }

after:

  void aaaaaaaaaaaaaaaaaaaaa(int c) {
    if (c) {
      f();
    }
    [dddddddddddddddddddddddddddddddddddddddddddddddddddddddd
      eeeeeeeeeeeeeeeeeeeeeeeeeeeee:^(fffffffffffffff gggggggg) {
        f(SSSSS, c);
      }];
  }


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99063

Files:
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/FormatTestObjC.cpp


Index: clang/unittests/Format/FormatTestObjC.cpp
===================================================================
--- clang/unittests/Format/FormatTestObjC.cpp
+++ clang/unittests/Format/FormatTestObjC.cpp
@@ -977,6 +977,19 @@
       "        performSelectorOnMainThread:@selector(loadAccessories)\n"
       "                         withObject:nil\n"
       "                      waitUntilDone:false];");
+
+  // The appropriate indentation is used after a block statement.
+  Style.ContinuationIndentWidth = 4;
+  verifyFormat(
+      "void aaaaaaaaaaaaaaaaaaaaa(int c) {\n"
+      "  if (c) {\n"
+      "    f();\n"
+      "  }\n"
+      "  [dddddddddddddddddddddddddddddddddddddddddddddddddddddddd\n"
+      "      eeeeeeeeeeeeeeeeeeeeeeeeeeeee:^(fffffffffffffff gggggggg) {\n"
+      "        f(SSSSS, c);\n"
+      "      }];\n"
+      "}");
 }
 
 TEST_F(FormatTestObjC, ObjCAt) {
Index: clang/lib/Format/UnwrappedLineParser.cpp
===================================================================
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -649,7 +649,6 @@
     nextToken();
 
   Line->Level = InitialLevel;
-  FormatTok->setBlockKind(BK_Block);
 
   if (PPStartHash == PPEndHash) {
     Line->MatchingOpeningBlockLineIndex = OpeningLineIndex;


Index: clang/unittests/Format/FormatTestObjC.cpp
===================================================================
--- clang/unittests/Format/FormatTestObjC.cpp
+++ clang/unittests/Format/FormatTestObjC.cpp
@@ -977,6 +977,19 @@
       "        performSelectorOnMainThread:@selector(loadAccessories)\n"
       "                         withObject:nil\n"
       "                      waitUntilDone:false];");
+
+  // The appropriate indentation is used after a block statement.
+  Style.ContinuationIndentWidth = 4;
+  verifyFormat(
+      "void aaaaaaaaaaaaaaaaaaaaa(int c) {\n"
+      "  if (c) {\n"
+      "    f();\n"
+      "  }\n"
+      "  [dddddddddddddddddddddddddddddddddddddddddddddddddddddddd\n"
+      "      eeeeeeeeeeeeeeeeeeeeeeeeeeeee:^(fffffffffffffff gggggggg) {\n"
+      "        f(SSSSS, c);\n"
+      "      }];\n"
+      "}");
 }
 
 TEST_F(FormatTestObjC, ObjCAt) {
Index: clang/lib/Format/UnwrappedLineParser.cpp
===================================================================
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -649,7 +649,6 @@
     nextToken();
 
   Line->Level = InitialLevel;
-  FormatTok->setBlockKind(BK_Block);
 
   if (PPStartHash == PPEndHash) {
     Line->MatchingOpeningBlockLineIndex = OpeningLineIndex;
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATCH] D99063: [clang-f... Krasimir Georgiev via Phabricator via cfe-commits

Reply via email to