This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] Fix AllowShortFunctionsOnASingleLine: InlineOnly with wrapping after record.
ClosedPublic

Authored by curdeius on Jan 27 2022, 2:46 AM.

Details

Summary

Fixes https://github.com/llvm/llvm-project/issues/53430.

Initially, I had a quick and dirty approach, but it led to a myriad of special cases handling comments (that may add unwrapped lines).
So I added TT_RecordLBrace type annotations and it seems like a much nicer solution.
I think that in the future it will allow us to clean up some convoluted code that detects records.

Diff Detail

Event Timeline

curdeius requested review of this revision.Jan 27 2022, 2:46 AM
curdeius created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptJan 27 2022, 2:46 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
curdeius added a project: Restricted Project.Jan 27 2022, 2:46 AM
MyDeveloperDay accepted this revision.Jan 27 2022, 3:19 AM
This revision is now accepted and ready to land.Jan 27 2022, 3:19 AM
MyDeveloperDay added inline comments.Jan 27 2022, 3:20 AM
clang/lib/Format/UnwrappedLineFormatter.cpp
280

we didn't need this anymore?

curdeius added inline comments.Jan 27 2022, 3:31 AM
clang/lib/Format/UnwrappedLineFormatter.cpp
280

Before it was handled in:

if (Style.isJavaScript() && RecordTok->is(Keywords.kw_function))
                  return true;
clang/unittests/Format/FormatTest.cpp
12348–12360

I know that some of these tests look weird but these were failing cases with a previous approach.

lichray added a subscriber: lichray.EditedJan 27 2022, 5:27 AM

Looks nice, and works for me (as in https://github.com/llvm/llvm-project/issues/53430).

+1 for the TokenAnnotatorTests, I think we need more of those instead of testing the formatted output.

This revision was landed with ongoing or failed builds.Jan 27 2022, 9:06 AM
This revision was automatically updated to reflect the committed changes.