This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] Improve UnwrappedLineParser::mightFitOnOneLine()
ClosedPublic

Authored by owenpan on Jan 1 2023, 7:21 PM.

Details

Summary

Account for an r_brace that precedes an "else if" statement when calculating whether the line might fit on one line if the r_brace is removed.

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

Diff Detail

Event Timeline

owenpan created this revision.Jan 1 2023, 7:21 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 1 2023, 7:21 PM
owenpan requested review of this revision.Jan 1 2023, 7:21 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 1 2023, 7:21 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
This revision is now accepted and ready to land.Jan 3 2023, 2:42 AM
HazardyKnusperkeks requested changes to this revision.

On second thought, shouldn't we test for removing the braces?

This revision now requires changes to proceed.Jan 3 2023, 6:53 AM

On second thought, shouldn't we test for removing the braces?

Hmm. This patch including the added test case is for removing braces.

On second thought, shouldn't we test for removing the braces?

Hmm. This patch including the added test case is for removing braces.

Then replace test with check.
I mean if we don't want to remove braces and the line than becomes to long, because we keep the brace. As far as I can see that could now happen right?

On second thought, shouldn't we test for removing the braces?

Hmm. This patch including the added test case is for removing braces.

Then replace test with check.

There is no test in my patch. What's check?

I mean if we don't want to remove braces and the line than becomes to long, because we keep the brace. As far as I can see that could now happen right?

If RemoveBracesLLVM is false, the line is too long and will wrap. If RemoveBracesLLVM is true, the line will fit on a single line after the braces are removed, However, without this patch, the braces would be kept and the line would wrap. (See the linked issue in the summary.)

If RemoveBracesLLVM is false, the line is too long and will wrap.

That's what I fail to see, but if you say so.

This revision is now accepted and ready to land.Jan 5 2023, 6:09 AM

If RemoveBracesLLVM is false, the line is too long and will wrap.

That's what I fail to see, but if you say so.

The line is 24 characters long, but ColumnLimit is set to 20 on line 731.