This is an archive of the discontinued LLVM Phabricator instance.

clang-format: Fixed line merging of more than two lines
ClosedPublic

Authored by mxbOctasic on Apr 13 2016, 9:10 AM.

Details

Summary

getNextMergedLine merged pairs of adjacent lines instead of merging them all with the first one.

Consider AnnotatedLine A, B and C.

The function merges A with B then B with C and returns a pointer to A.
A.Last is not updated when B and C are merged together. (A.Last == B.Last)

Subsequent lines need to be merged with the first.
By merging A with B then with C, A.Last points to the proper token. (A.Last == C.Last)

Diff Detail

Repository
rL LLVM

Event Timeline

mxbOctasic updated this revision to Diff 53572.Apr 13 2016, 9:10 AM
mxbOctasic retitled this revision from to clang-format: Fixed line merging of more than two lines.
mxbOctasic updated this object.
mxbOctasic added a reviewer: djasper.
mxbOctasic added subscribers: cameron314, cfe-commits.
djasper edited edge metadata.Apr 13 2016, 12:42 PM

Nice catch.

unittests/Format/FormatTest.cpp
285 ↗(On Diff #53572)

How does this break? I generally add an Before and After of one of the test cases into my patch descriptions.

mxbOctasic added inline comments.Apr 13 2016, 1:34 PM
unittests/Format/FormatTest.cpp
285 ↗(On Diff #53572)

This is a fun one.

The newline between Foo() {} and void Funk() {} is removed.
This is a combination of the line merge problem and KeepEmptyLinesAtTheStartOfBlocks.

Last on the merged line for Foo() {} points to { instead of }, so the newline before void is seen as a newline at the start of a block. (Checks PreviousLine->Last->is(tok::l_brace))

djasper accepted this revision.Oct 4 2016, 11:23 PM
djasper edited edge metadata.

Sorry for the delay. Looks good.

This revision is now accepted and ready to land.Oct 4 2016, 11:23 PM

I'll commit this in a few days, when I have some time to reintegrate it to the trunk. Thanks!

This revision was automatically updated to reflect the committed changes.