This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] Handle do-while loops for RemoveBracesLLVM
ClosedPublic

Authored by owenpan on Jun 1 2022, 1:29 AM.

Details

Summary

If a do-while loop is in the block of a control statement, do not remove the braces.

Also updates the unit tests to match the updated LLVM Coding Standards. (See D126512.)

Diff Detail

Event Timeline

owenpan created this revision.Jun 1 2022, 1:29 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 1 2022, 1:29 AM
owenpan requested review of this revision.Jun 1 2022, 1:29 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 1 2022, 1:29 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
curdeius accepted this revision.Jun 1 2022, 3:26 AM
curdeius added inline comments.
clang/unittests/Format/FormatTest.cpp
25103

Nit. To avoid updating it every time we add an example.

25407–25411

What's the value of testing that newlines are added? That's not really the job of Insert/RemoveBraces.

This revision is now accepted and ready to land.Jun 1 2022, 3:26 AM
owenpan added inline comments.Jun 1 2022, 9:23 AM
clang/unittests/Format/FormatTest.cpp
25103

Yep. I will also remove the numbering on the examples.

25407–25411

This was from the actual llvm-project source. I used it not because I wanted to test the insertion of newlines, but because I fixed some insert/remove braces bugs related to whether the braces were wrapped.

owenpan updated this revision to Diff 433432.Jun 1 2022, 9:38 AM

Removed the numbering of the examples from the coding standards.

owenpan marked an inline comment as done.Jun 1 2022, 9:38 AM
clang/lib/Format/UnwrappedLineParser.h
118–119

Should we merge that to something like KeepBraces? Or do we use HasLabel and HasDoWhile differently?

owenpan added inline comments.Jun 1 2022, 3:36 PM
clang/lib/Format/UnwrappedLineParser.h
118–119

We will use them differently. There will be no configuration for labels but some configurations for do-while loops eventually.

HazardyKnusperkeks added inline comments.
clang/lib/Format/UnwrappedLineParser.h
118–119

Ok.

This revision was landed with ongoing or failed builds.Jun 2 2022, 1:08 AM
This revision was automatically updated to reflect the committed changes.