[PATCH] D146434: [clang-format] Fix support for ObjC blocks with pointer return types
Jared Grubb via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 14 10:36:19 PDT 2023
jaredgrubb updated this revision to Diff 540488.
jaredgrubb marked an inline comment as done.
jaredgrubb added a comment.
Address review comment and rebase to re-run tests. Intend to merge if everything is green! (If there are further comments, I will commit to address them!)
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D146434/new/
https://reviews.llvm.org/D146434
Files:
clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/FormatTest.cpp
clang/unittests/Format/FormatTestObjC.cpp
Index: clang/unittests/Format/FormatTestObjC.cpp
===================================================================
--- clang/unittests/Format/FormatTestObjC.cpp
+++ clang/unittests/Format/FormatTestObjC.cpp
@@ -1019,6 +1019,20 @@
verifyFormat("int (^foo[kNumEntries])(char, float);");
verifyFormat("int (^foo[kNumEntries + 10])(char, float);");
verifyFormat("int (^foo[(kNumEntries + 10)])(char, float);");
+
+ verifyFormat("int *p = ^int *() { //\n"
+ " return nullptr;\n"
+ "}();");
+
+ verifyFormat("int * (^p)(void) = ^int *(void) { //\n"
+ " return nullptr;\n"
+ "};");
+
+ // WebKit forces function braces onto a newline, but blocks should not.
+ verifyFormat("int* p = ^int*() { //\n"
+ " return nullptr;\n"
+ "}();",
+ getWebKitStyle());
}
TEST_F(FormatTestObjC, ObjCSnippets) {
Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -22619,7 +22619,8 @@
" }\n"
" }\n"
"});");
- verifyFormat("Block b = ^int *(A *a, B *b) {}");
+ verifyFormat("Block b = ^int *(A *a, B *b) {\n"
+ "};");
verifyFormat("BOOL (^aaa)(void) = ^BOOL {\n"
"};");
Index: clang/lib/Format/UnwrappedLineParser.cpp
===================================================================
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1798,12 +1798,18 @@
break;
case tok::caret:
nextToken();
+ // Block return type.
if (FormatTok->Tok.isAnyIdentifier() ||
FormatTok->isSimpleTypeSpecifier()) {
nextToken();
+ // Return types: pointers are ok too.
+ while (FormatTok->is(tok::star))
+ nextToken();
}
+ // Block argument list.
if (FormatTok->is(tok::l_paren))
parseParens();
+ // Block body.
if (FormatTok->is(tok::l_brace))
parseChildBlock();
break;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D146434.540488.patch
Type: text/x-patch
Size: 2157 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230714/3d6f66b1/attachment.bin>
More information about the cfe-commits
mailing list