Author: Krasimir Georgiev Date: 2021-03-25T10:52:08+01:00 New Revision: d9abcdd9f471ab0d986197e94498a5cf90aa12ef
URL: https://github.com/llvm/llvm-project/commit/d9abcdd9f471ab0d986197e94498a5cf90aa12ef DIFF: https://github.com/llvm/llvm-project/commit/d9abcdd9f471ab0d986197e94498a5cf90aa12ef.diff LOG: [clang-format] Fix ObjC method indent after f7f9f94b 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); }]; } ``` Differential Revision: https://reviews.llvm.org/D99063 Added: Modified: clang/lib/Format/UnwrappedLineParser.cpp clang/unittests/Format/FormatTestObjC.cpp Removed: ################################################################################ diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index 1404d4a8eaeb..e424fcb34219 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -649,7 +649,6 @@ void UnwrappedLineParser::parseBlock(bool MustBeDeclaration, unsigned AddLevels, nextToken(); Line->Level = InitialLevel; - FormatTok->setBlockKind(BK_Block); if (PPStartHash == PPEndHash) { Line->MatchingOpeningBlockLineIndex = OpeningLineIndex; diff --git a/clang/unittests/Format/FormatTestObjC.cpp b/clang/unittests/Format/FormatTestObjC.cpp index c33f93bcf99d..aa27f6ecf93b 100644 --- a/clang/unittests/Format/FormatTestObjC.cpp +++ b/clang/unittests/Format/FormatTestObjC.cpp @@ -977,6 +977,19 @@ TEST_F(FormatTestObjC, FormatObjCMethodExpr) { " 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) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits