Page MenuHomePhabricator

[clang-format] Fix support for ObjC blocks with pointer return types
AcceptedPublic

Authored by jaredgrubb on Mar 20 2023, 9:31 AM.

Details

Summary

The ObjC-block detection code only supports a single token as the return type. Add support to detect pointers, too (ObjC has lots of object-pointers).

For example, using BasedOnStyle: WebKit, the following is stable output:

int* p = ^int*(void)
{ //
    return nullptr;
}
();

After the patch:

int* p = ^int*(void) { //
    return nullptr;
}();

Diff Detail

Event Timeline

jaredgrubb created this revision.Mar 20 2023, 9:31 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 20 2023, 9:31 AM
jaredgrubb requested review of this revision.Mar 20 2023, 9:31 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 20 2023, 9:31 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
MyDeveloperDay added inline comments.
clang/unittests/Format/FormatTest.cpp
22178

I don’t like us changing tests

jaredgrubb added inline comments.Mar 20 2023, 8:43 PM
clang/unittests/Format/FormatTest.cpp
22178

Normally I would agree, but in this case, this is a bug-fix for the test as well.

If you look at the verifyFormat just below this one, its braces are broken across separate lines. The inconsistency between these two tests was due to the difference in the block's return type (pointer vs non-pointer).

My patch corrects exactly that inconsistency.

This revision is now accepted and ready to land.Mar 21 2023, 3:14 AM
owenpan added inline comments.Mar 23 2023, 9:57 PM
clang/lib/Format/UnwrappedLineParser.cpp
1779–1782
clang/unittests/Format/FormatTestObjC.cpp
1007–1010