This is an archive of the discontinued LLVM Phabricator instance.

clang-format: use AfterControlStatement to format ObjC control blocks
ClosedPublic

Authored by Typz on Feb 13 2018, 5:20 AM.

Details

Summary

ObjC defines @autoreleasepool and @synchronized control blocks. These
used to be formatted according to the AfterObjCDeclaration brace-
wrapping flag, which is not very consistent.

This patch changes the behavior to use the AfterControlStatement flag
instead. This should not affect the behavior unless a custom brace
wrapping mode is used.

Diff Detail

Event Timeline

Typz created this revision.Feb 13 2018, 5:20 AM
Typz added a comment.Feb 13 2018, 5:24 AM

This is done as discussed in https://reviews.llvm.org/D43114.
But I can instead add a new AfterObjCSpecialBlock brace wrapping flag.

benhamilton requested changes to this revision.Feb 14 2018, 12:34 PM

Thanks! Can you add a test for this, please?

This revision now requires changes to proceed.Feb 14 2018, 12:34 PM
Typz added a comment.Feb 15 2018, 7:36 AM

Thanks! Can you add a test for this, please?

There are actually tests, though they are performed by activating Allman brace wrapping mode.
I am trying to change them, but this highlights another issue: when only AfterControlStatement is set, the block gets inlined, like this:

@autoreleasepool
{ f(); }

This used to happen before as well, and would require fixing UnwrappedLineFormatter.cpp to understand that these blocks are linked to the previous ObjC keyword.

This used to happen before as well, and would require fixing UnwrappedLineFormatter.cpp to understand that these blocks are linked to the previous ObjC keyword.

Good find! Looks like we should fix that and add some more tests with AfterControlStatement set to true and to false.

Typz added a comment.Feb 15 2018, 8:11 AM

I'll try to fix this.

Can you please review D43114 in the mean time? This patch depends on it, so it must be merged first.

Typz updated this revision to Diff 134641.Feb 16 2018, 9:05 AM

Fix bug which was lingering: prevent inlining of ObjC special control blocks.

benhamilton accepted this revision.Feb 16 2018, 9:20 AM
This revision is now accepted and ready to land.Feb 16 2018, 9:20 AM
This revision was automatically updated to reflect the committed changes.