This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] Handle trailing comment for InsertBraces
ClosedPublic

Authored by owenpan on Feb 24 2022, 10:29 AM.

Diff Detail

Event Timeline

owenpan requested review of this revision.Feb 24 2022, 10:29 AM
owenpan created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptFeb 24 2022, 10:29 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
This revision is now accepted and ready to land.Feb 24 2022, 12:16 PM
clang/lib/Format/UnwrappedLineParser.cpp
2338–2339

So basically one would just need a Line.isComment() or so? The lastNonComment is not important, right?

owenpan updated this revision to Diff 411256.Feb 24 2022, 4:18 PM
  • Simplified the code that backtracks to the token which the right braces are to be inserted after.
  • Added a missing newline in the new testcase.
owenpan added inline comments.Feb 24 2022, 4:19 PM
clang/lib/Format/UnwrappedLineParser.cpp
2338–2339

We don't really need a pointer to the last non-comment token here as we would return the last token of the line, but the pointer is still needed for the left brace above.

owenpan added inline comments.Feb 24 2022, 11:10 PM
clang/lib/Format/UnwrappedLineParser.cpp
2338–2339

We have to try to find either the first or the last non-comment token in L to determine if it's a comment line, for L can be something like:

/* comment */ f(); // comment
This revision was landed with ongoing or failed builds.Feb 25 2022, 12:30 PM
This revision was automatically updated to reflect the committed changes.