[PATCH] D121451: [clang-format] Add space to comments starting with '#'.

Krasimir Georgiev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 21 03:06:32 PDT 2022


krasimir added a comment.

This is getting more fun: the reason why `///` isn't broken up is because the first character `/` after the comment leader `//` is considered punctuation per isPunctuation's CHAR_RAWDEL, which includes all these `{}[]#<>%:;?*+-/^&|~!=,"'`:

- https://github.com/llvm/llvm-project/blob/73a15ad567071c13e761fd6d593e2b66164865e2/clang/lib/Format/BreakableToken.cpp#L790
- https://github.com/llvm/llvm-project/blob/73a15ad567071c13e761fd6d593e2b66164865e2/clang/include/clang/Basic/CharInfo.h#L139
- https://github.com/llvm/llvm-project/blob/73a15ad567071c13e761fd6d593e2b66164865e2/clang/include/clang/Basic/CharInfo.h#L31

With this patch, we got stuff like:

  % cat test.cc
  //# status
  //. status
  //; status
  //{ status
  /// status
  //, status
  //: status
  % ~/llvm/llvm-project/build/bin/clang-format test.cc
  // # status
  //. status
  //; status
  //{ status
  /// status
  //, status
  //: status

This makes me think that we should really consider not adding indent if the first character is punctuation WAI, with rationale:

- comments starting with such characters often have special meaning, clang-format errors out on the conservative side to not touch them. Example is stuff like `//!` in Doxygen blocks: https://www.doxygen.nl/manual/docblocks.html
- it's possible to work around this by changing the source code to use `// #`; clang-format will respect indentation in that case (also for other punctuation characters).

WDYAT?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121451/new/

https://reviews.llvm.org/D121451



More information about the cfe-commits mailing list