[clang] [clang-format] Option to insert spaces before the closing `*/` (PR #162105)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 20 07:11:50 PST 2025
================
@@ -1387,6 +1403,21 @@ FormatToken *FormatTokenLexer::getNextToken() {
StringRef UntrimmedText = FormatTok->TokenText;
FormatTok->TokenText = FormatTok->TokenText.rtrim(" \t\v\f");
TrailingWhitespace = UntrimmedText.size() - FormatTok->TokenText.size();
+
+ if (isWellFormedBlockCommentText(FormatTok->TokenText)) {
+ FormatTok->setBlockCommentKind(
+ classifyBlockComment(FormatTok->TokenText));
+ const StringRef Content =
+ FormatTok->TokenText.drop_front(2).drop_back(2).rtrim("\r\n");
+ if (!Content.empty()) {
+ const auto LastChar = static_cast<unsigned char>(Content.back());
+ if (!isHorizontalWhitespace(LastChar)) {
+ FormatTok->NeedsSpaceBeforeClosingBlockComment = true;
+ FormatTok->SpaceBeforeClosingBlockCommentOffset =
+ FormatTok->TokenText.size() - 2;
----------------
Men-cotton wrote:
Thanks for the suggestion.
I've refactored the whitespace management to be handled within `BreakableBlockComment::adaptStartOfLine`.
Although this runs during the initial adaptation phase (preceding the core reflow), it fits naturally into the comment formatting pipeline and eliminates the need to save external state. This version is much simpler.
https://github.com/llvm/llvm-project/pull/162105
More information about the cfe-commits
mailing list