[clang] [clang-format] adds a space after not inside macros (PR #78176)
Ilya Biryukov via cfe-commits
cfe-commits at lists.llvm.org
Mon Jan 15 09:36:30 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)) {
----------------
ilya-biryukov wrote:
I have used `!` merely as an example, I feel that we should probably not add space for almost all tokens:
```cpp
#define str(X) #X
#define v(X) str(foo##X)
char *x = v(not;);
char *y = v(not+);
```
The only exception I see are identifiers and numeric literals (as they will combine the tokens together):
```cpp
v(not x)
v(not 1)
v(not 123.f)
```
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.
https://github.com/llvm/llvm-project/pull/78176
More information about the cfe-commits
mailing list