Page MenuHomePhabricator

[clang-format] Parse blocks in braced lists
AbandonedPublic

Authored by strager on Nov 18 2017, 7:21 PM.

Details

Summary

clang-format completely ruins the formatting of block literal
expressions which appear inside inside braced initializer lists. For
example:

int main() {
  foo({
      ^() {
        return nil;
}
});
}

Teach clang-format to parse blocks inside braced lists:

int main() {
  foo({^() {
    return nil;
  }});
}

Event Timeline

strager created this revision.Nov 18 2017, 7:21 PM
strager edited the summary of this revision. (Show Details)Nov 18 2017, 7:22 PM
strager edited the summary of this revision. (Show Details)
compnerd added a subscriber: compnerd.
benhamilton edited reviewers, added: klimek; removed: djasper.May 23 2018, 8:38 AM

@djasper isn't available to review.

At a high level, this seems good, but I'd like @klimek to take a look.

lib/Format/UnwrappedLineParser.cpp
1320

Is it standard to return a value from these tryToParseFoo() methods, even if nobody uses it?

I think we should either check the return value somewhere, or make this return void.

1324–1327

Style: Remove curly braces for one-line if blocks.

strager abandoned this revision.Oct 10 2019, 6:41 PM
klimek added inline comments.Oct 11 2019, 12:34 AM
lib/Format/UnwrappedLineParser.cpp
1324

Isn't this only an Obj-C/Obj-C++ thing?
If it is, I'd call it tryToParseObjCBlockLiteral.

MyDeveloperDay added a project: Restricted Project.Oct 11 2019, 2:18 AM