[clang] [clang-format] adds a space after not inside macros (PR #78176)

Owen Pan via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 15 17:27:11 PST 2024


================
@@ -4842,7 +4842,7 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
     return true;
   }
   if (Left.is(TT_UnaryOperator)) {
-    if (Right.isNot(tok::l_paren)) {
+    if (!Right.isOneOf(tok::r_paren, tok::l_paren, tok::exclaim)) {
----------------
owenca wrote:

> The only exception I see are identifiers and numeric literals (as they will combine the tokens together):
> 
> ```c++
> v(not x)
> v(not 1)
> v(not 123.f)
> ```

+1.

> Should this condition be something like `if (Right.isOneOf(tok::ident, /*... numeric literals*/))`? Or will this cause us to not add spaces in undesired places?
> 
> If we can avoid those spaces for only a limited set of tokens, I would probably limit this to `tok::lparen` and `tok::rparen`, the rest seems much less likely.

We should come up with a more general fix.

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


More information about the cfe-commits mailing list