[clang] [clang-format] Option to insert spaces before the closing `*/` (PR #162105)

via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 28 18:51:07 PDT 2025


================
@@ -18,11 +18,66 @@
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Format/Format.h"
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/Regex.h"
 
 namespace clang {
 namespace format {
 
+namespace {
+
+CommentKind classifyBlockComment(StringRef Text) {
+  if (!Text.starts_with("/*") || !Text.ends_with("*/"))
----------------
Men-cotton wrote:

Thanks for pointing that out!

In the previous revision I still called `classifyBlockComment` before checking `isWellFormedBlockCommentText`, so line comments such as `//x` slipped through and would have hit the `drop_front(2).drop_back(2)` path, triggering an assertion. I’ve now moved the call so it only runs after `isWellFormedBlockCommentText` succeeds, which guarantees we only classify well-formed block comments. With that change the guard inside `classifyBlockComment` can’t fire anymore, so I removed it in the latest patch.

https://github.com/llvm/llvm-project/pull/162105


More information about the cfe-commits mailing list